Bug 1362215 - use MOZ_FORMAT_PRINTF in TestHarness.h; r?froydnj draft
authorTom Tromey <tom@tromey.com>
Fri, 05 May 2017 14:23:00 -0600
changeset 574313 d6fefc66589efb7a25055c6b568180dbc20ec02c
parent 574221 b2bec2797b6d967c762e4ff2423c55702e5a862d
child 627544 0ce7318757a84784b332d7839174e02d4ff2799c
push id57653
push userbmo:ttromey@mozilla.com
push dateMon, 08 May 2017 17:19:58 +0000
reviewersfroydnj
bugs1362215
milestone55.0a1
Bug 1362215 - use MOZ_FORMAT_PRINTF in TestHarness.h; r?froydnj MozReview-Commit-ID: JtNSFoowLIv
tools/fuzzing/libfuzzer/harness/LibFuzzerTestHarness.h
xpcom/tests/TestHarness.h
--- a/tools/fuzzing/libfuzzer/harness/LibFuzzerTestHarness.h
+++ b/tools/fuzzing/libfuzzer/harness/LibFuzzerTestHarness.h
@@ -8,16 +8,17 @@
  * nsCOMPtr, nsRefPtr, do_CreateInstance, do_GetService, ns(Auto|C|)String,
  * and stdio.h/stdlib.h.
  */
 
 #ifndef LibFuzzerTestHarness_h__
 #define LibFuzzerTestHarness_h__
 
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/Attributes.h"
 
 #include "prenv.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsStringGlue.h"
 #include "nsAppDirectoryServiceDefs.h"
@@ -36,17 +37,17 @@ namespace {
 
 static uint32_t gFailCount = 0;
 
 /**
  * Prints the given failure message and arguments using printf, prepending
  * "TEST-UNEXPECTED-FAIL " for the benefit of the test harness and
  * appending "\n" to eliminate having to type it at each call site.
  */
-void fail(const char* msg, ...)
+MOZ_FORMAT_PRINTF(1, 2) void fail(const char* msg, ...)
 {
   va_list ap;
 
   printf("TEST-UNEXPECTED-FAIL | ");
 
   va_start(ap, msg);
   vprintf(msg, ap);
   va_end(ap);
@@ -55,17 +56,17 @@ void fail(const char* msg, ...)
   ++gFailCount;
 }
 
 /**
  * Prints the given success message and arguments using printf, prepending
  * "TEST-PASS " for the benefit of the test harness and
  * appending "\n" to eliminate having to type it at each call site.
  */
-void passed(const char* msg, ...)
+MOZ_FORMAT_PRINTF(1, 2) void passed(const char* msg, ...)
 {
   va_list ap;
 
   printf("TEST-PASS | ");
 
   va_start(ap, msg);
   vprintf(msg, ap);
   va_end(ap);
--- a/xpcom/tests/TestHarness.h
+++ b/xpcom/tests/TestHarness.h
@@ -8,16 +8,17 @@
  * nsCOMPtr, nsRefPtr, do_CreateInstance, do_GetService, ns(Auto|C|)String,
  * and stdio.h/stdlib.h.
  */
 
 #ifndef TestHarness_h__
 #define TestHarness_h__
 
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/Attributes.h"
 
 #include "prenv.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsStringGlue.h"
 #include "nsAppDirectoryServiceDefs.h"
@@ -34,17 +35,17 @@
 
 static uint32_t gFailCount = 0;
 
 /**
  * Prints the given failure message and arguments using printf, prepending
  * "TEST-UNEXPECTED-FAIL " for the benefit of the test harness and
  * appending "\n" to eliminate having to type it at each call site.
  */
-void fail(const char* msg, ...)
+MOZ_FORMAT_PRINTF(1, 2) void fail(const char* msg, ...)
 {
   va_list ap;
 
   printf("TEST-UNEXPECTED-FAIL | ");
 
   va_start(ap, msg);
   vprintf(msg, ap);
   va_end(ap);
@@ -53,17 +54,17 @@ void fail(const char* msg, ...)
   ++gFailCount;
 }
 
 /**
  * Prints the given success message and arguments using printf, prepending
  * "TEST-PASS " for the benefit of the test harness and
  * appending "\n" to eliminate having to type it at each call site.
  */
-void passed(const char* msg, ...)
+MOZ_FORMAT_PRINTF(1, 2) void passed(const char* msg, ...)
 {
   va_list ap;
 
   printf("TEST-PASS | ");
 
   va_start(ap, msg);
   vprintf(msg, ap);
   va_end(ap);
@@ -83,17 +84,17 @@ class ScopedXPCOM : public nsIDirectoryS
     : mDirSvcProvider(dirSvcProvider)
     {
       mTestName = testName;
       printf("Running %s tests...\n", mTestName);
 
       nsresult rv = NS_InitXPCOM2(&mServMgr, nullptr, this);
       if (NS_FAILED(rv))
       {
-        fail("NS_InitXPCOM2 returned failure code 0x%x", rv);
+        fail("NS_InitXPCOM2 returned failure code 0x%" PRIx32, static_cast<uint32_t>(rv));
         mServMgr = nullptr;
         return;
       }
     }
 
     ~ScopedXPCOM()
     {
       // If we created a profile directory, we need to remove it.
@@ -115,17 +116,17 @@ class ScopedXPCOM : public nsIDirectoryS
       }
 
       if (mServMgr)
       {
         NS_RELEASE(mServMgr);
         nsresult rv = NS_ShutdownXPCOM(nullptr);
         if (NS_FAILED(rv))
         {
-          fail("XPCOM shutdown failed with code 0x%x", rv);
+          fail("XPCOM shutdown failed with code 0x%" PRIx32, static_cast<uint32_t>(rv));
           exit(1);
         }
       }
 
       printf("Finished running %s tests.\n", mTestName);
     }
 
     bool failed()