Bug 1369622 - Add a static_assert when no variadic argument is given to MOZ_CRASH_UNSAFE_PRINTF. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 02 Jun 2017 15:11:47 +0900
changeset 412999 e1a83fc8ff4fdf2cfd16511363435102cf798d20
parent 412998 f360dd9d411e7ba61531bed2c32a0981cc6c418a
child 413000 8a8f6ea6d05652f93cff34147e3934c702a6bade
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1369622
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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