Bug 1362215 - use MOZ_FORMAT_PRINTF in TestHarness.h; r?froydnj
MozReview-Commit-ID: JtNSFoowLIv
--- 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()