tests: set output_file to a valid value
authorLudovic Rousseau <ludovic.rousseau+github@gmail.com>
Sun, 22 Sep 2013 19:29:50 +0000 (21:29 +0200)
committerLudovic Rousseau <ludovic.rousseau+github@gmail.com>
Sat, 28 Sep 2013 10:19:16 +0000 (12:19 +0200)
If fdopen(3) fails then ctx->output_file is NULL and should not be used
in cleanup_test_output() called next.

Problem detected by the Coverity tool
CID 1042543 (#1 of 1): Dereference after null check (FORWARD_NULL)9.
var_deref_model: Passing "ctx" to function
"cleanup_test_output(libusbx_testlib_ctx *)", which dereferences null
"ctx->output_file".

libusb/version_nano.h
tests/testlib.c

index 2000b91..ac86199 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10842
+#define LIBUSB_NANO 10843
index e69aa39..7cab0b9 100644 (file)
@@ -139,6 +139,7 @@ static int setup_test_output(libusbx_testlib_ctx * ctx)
                }
                ctx->output_file = fdopen(ctx->old_stdout, "w");
                if (!ctx->output_file) {
+                       ctx->output_file = stdout;
                        cleanup_test_output(ctx);
                        printf("Failed to open FILE for output handle: %d\n", errno);
                        return 1;