Do not send a NULL C-style string to std::ostream.
The res_filename field of the DecodeParam struct is a C-style string. We
allow it to be a NULL pointer. Before we send a NULL C-style string to
std::ostream, convert it to a valid C++ string. Better yet, convert it to
the default result file name.
BUG=aomedia:2282,aomedia:2396
Change-Id: I161e1268ea7cf273a70d9a7ff22044078b632038
diff --git a/test/invalid_file_test.cc b/test/invalid_file_test.cc
index 8a42a9e..c2f128c 100644
--- a/test/invalid_file_test.cc
+++ b/test/invalid_file_test.cc
@@ -27,9 +27,16 @@
// filename + ".res".
};
+// Constructs result file name.
+std::string GetResFilename(const DecodeParam ¶m) {
+ if (param.res_filename != NULL) return param.res_filename;
+ const std::string filename = param.filename;
+ return filename + ".res";
+}
+
std::ostream &operator<<(std::ostream &os, const DecodeParam &dp) {
return os << "threads: " << dp.threads << " file: " << dp.filename
- << " result file: " << dp.res_filename;
+ << " result file: " << GetResFilename(dp);
}
class InvalidFileTest : public ::libaom_test::DecoderTest,
@@ -99,13 +106,10 @@
libaom_test::IVFVideoSource decode_video(filename);
decode_video.Init();
- // Construct result file name. The file holds a list of expected integer
- // results, one for each decoded frame. Any result that doesn't match
- // the file's list will cause a test failure.
- std::string res_filename = filename + ".res";
- if (input.res_filename != NULL) {
- res_filename = input.res_filename;
- }
+ // The result file holds a list of expected integer results, one for each
+ // decoded frame. Any result that doesn't match the file's list will
+ // cause a test failure.
+ const std::string res_filename = GetResFilename(input);
OpenResFile(res_filename);
ASSERT_NO_FATAL_FAILURE(RunLoop(&decode_video, cfg));