Bug 1369622 - Add a static_assert when no variadic argument is given to MOZ_CRASH_UNSAFE_PRINTF. r?froydnj draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 02 Jun 2017 15:11:47 +0900
changeset 588097 3cd7508fbf53d1be94174a9a795378acd0556110
parent 588096 dbf0550621ba1346d6fe2332c54104fb9912fe81
child 631462 95cf5d5f1b69fc91d2033c0920b8230e5ed6961f
push id61910
push userbmo:mh+mozilla@glandium.org
push dateFri, 02 Jun 2017 06:13:28 +0000
reviewersfroydnj
bugs1369622
milestone55.0a1
Bug 1369622 - Add a static_assert when no variadic argument is given to MOZ_CRASH_UNSAFE_PRINTF. r?froydnj If MOZ_CRASH_UNSAFE_PRINTF is only given a format string, it means either arguments are missing, or MOZ_CRASH should be used instead. Hint at that with a static_assert.
mfbt/Assertions.h
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -310,16 +310,20 @@ MOZ_CrashPrintf(const char* aFilename, i
  * a printf-style format string, which must be a string literal and between
  * 1 and 4 additional arguments. A regular MOZ_CRASH() is preferred wherever
  * possible, as passing arbitrary strings to printf from a potentially
  * compromised process is not without risk.
  */
 #define MOZ_CRASH_UNSAFE_PRINTF(format, ...) \
    do { \
      static_assert( \
+       MOZ_ARG_COUNT(__VA_ARGS__) > 0, \
+       "Did you forget arguments to MOZ_CRASH_UNSAFE_PRINTF? " \
+       "Or maybe you want MOZ_CRASH instead?"); \
+     static_assert( \
        MOZ_ARG_COUNT(__VA_ARGS__) <= sPrintfMaxArgs, \
        "Only up to 4 additional arguments are allowed!"); \
      static_assert(sizeof(format) <= sPrintfCrashReasonSize, \
        "The supplied format string is too long!"); \
      MOZ_CALL_CRASH_PRINTF("" format, __VA_ARGS__); \
    } while (0)
 
 MOZ_END_EXTERN_C