Bug 1334279 - mark vsprintf-likes with MOZ_FORMAT_PRINTF; r=froydnj

This annotates vsprintf-like functions with MOZ_FORMAT_PRINTF.  This may
provide some minimal checking of such calls (the GCC docs say that it
checks for the string for "consistency"); but in any case shouldn't
hurt.

MozReview-Commit-ID: HgnAK1LiorE

--HG--
extra : rebase_source : 9c8d715d6560f89078c26ba3934e52a2b5778b6a
This commit is contained in:
Tom Tromey 2017-05-04 12:10:19 -06:00
parent 8fef752ced
commit aa6e054b71
16 changed files with 28 additions and 18 deletions

View file

@ -2054,7 +2054,7 @@ protected:
public: public:
// console logging helpers // console logging helpers
void GenerateWarning(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3); void GenerateWarning(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3);
void GenerateWarning(const char* fmt, va_list ap); void GenerateWarning(const char* fmt, va_list ap) MOZ_FORMAT_PRINTF(2, 0);
void GeneratePerfWarning(const char* fmt, ...) const MOZ_FORMAT_PRINTF(2, 3); void GeneratePerfWarning(const char* fmt, ...) const MOZ_FORMAT_PRINTF(2, 3);

View file

@ -183,9 +183,9 @@ void JitSpewCont(JitSpewChannel channel, const char* fmt, ...) MOZ_FORMAT_PRINTF
void JitSpewFin(JitSpewChannel channel); void JitSpewFin(JitSpewChannel channel);
void JitSpewHeader(JitSpewChannel channel); void JitSpewHeader(JitSpewChannel channel);
bool JitSpewEnabled(JitSpewChannel channel); bool JitSpewEnabled(JitSpewChannel channel);
void JitSpewVA(JitSpewChannel channel, const char* fmt, va_list ap); void JitSpewVA(JitSpewChannel channel, const char* fmt, va_list ap) MOZ_FORMAT_PRINTF(2, 0);
void JitSpewStartVA(JitSpewChannel channel, const char* fmt, va_list ap); void JitSpewStartVA(JitSpewChannel channel, const char* fmt, va_list ap) MOZ_FORMAT_PRINTF(2, 0);
void JitSpewContVA(JitSpewChannel channel, const char* fmt, va_list ap); void JitSpewContVA(JitSpewChannel channel, const char* fmt, va_list ap) MOZ_FORMAT_PRINTF(2, 0);
void JitSpewDef(JitSpewChannel channel, const char* str, MDefinition* def); void JitSpewDef(JitSpewChannel channel, const char* str, MDefinition* def);
void EnableChannel(JitSpewChannel channel); void EnableChannel(JitSpewChannel channel);
@ -253,7 +253,8 @@ static inline void JitSpewHeader(JitSpewChannel channel)
{ } { }
static inline bool JitSpewEnabled(JitSpewChannel channel) static inline bool JitSpewEnabled(JitSpewChannel channel)
{ return false; } { return false; }
static inline void JitSpewVA(JitSpewChannel channel, const char* fmt, va_list ap) static inline MOZ_FORMAT_PRINTF(2, 0)
void JitSpewVA(JitSpewChannel channel, const char* fmt, va_list ap)
{ } { }
static inline void JitSpewDef(JitSpewChannel channel, const char* str, MDefinition* def) static inline void JitSpewDef(JitSpewChannel channel, const char* str, MDefinition* def)
{ } { }

View file

@ -77,7 +77,7 @@ class MIRGenerator
abort(AbortReason r, const char* message, ...) MOZ_FORMAT_PRINTF(3, 4); abort(AbortReason r, const char* message, ...) MOZ_FORMAT_PRINTF(3, 4);
mozilla::GenericErrorResult<AbortReason> mozilla::GenericErrorResult<AbortReason>
abortFmt(AbortReason r, const char* message, va_list ap); abortFmt(AbortReason r, const char* message, va_list ap) MOZ_FORMAT_PRINTF(3, 0);
// Collect the evaluation result of phases after IonBuilder, such that // Collect the evaluation result of phases after IonBuilder, such that
// off-thread compilation can report what error got encountered. // off-thread compilation can report what error got encountered.

View file

@ -1317,7 +1317,7 @@ class Assembler : public AssemblerShared
uint32_t spewProbe(Label* l); uint32_t spewProbe(Label* l);
uint32_t spewDefine(Label* l); uint32_t spewDefine(Label* l);
void spew(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3); void spew(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3);
void spew(const char* fmt, va_list args); void spew(const char* fmt, va_list args) MOZ_FORMAT_PRINTF(2, 0);
#endif #endif
public: public:

View file

@ -223,7 +223,7 @@ namespace jit {
} }
#ifdef JS_JITSPEW #ifdef JS_JITSPEW
MOZ_COLD void spew(const char* fmt, va_list va); MOZ_COLD void spew(const char* fmt, va_list va) MOZ_FORMAT_PRINTF(2, 0);
#endif #endif
}; };

View file

@ -1024,7 +1024,7 @@ SelfHostedFunction(JSContext* cx, HandlePropertyName propName);
#ifdef va_start #ifdef va_start
extern bool extern bool
ReportErrorVA(JSContext* cx, unsigned flags, const char* format, ReportErrorVA(JSContext* cx, unsigned flags, const char* format,
ErrorArgumentsType argumentsType, va_list ap); ErrorArgumentsType argumentsType, va_list ap) MOZ_FORMAT_PRINTF(3, 0);
extern bool extern bool
ReportErrorNumberVA(JSContext* cx, unsigned flags, JSErrorCallback callback, ReportErrorNumberVA(JSContext* cx, unsigned flags, JSErrorCallback callback,

View file

@ -26,8 +26,10 @@ extern JS_PUBLIC_API(JS::UniqueChars) JS_sprintf_append(JS::UniqueChars&& last,
const char* fmt, ...) const char* fmt, ...)
MOZ_FORMAT_PRINTF(2, 3); MOZ_FORMAT_PRINTF(2, 3);
extern JS_PUBLIC_API(JS::UniqueChars) JS_vsmprintf(const char* fmt, va_list ap); extern JS_PUBLIC_API(JS::UniqueChars) JS_vsmprintf(const char* fmt, va_list ap)
MOZ_FORMAT_PRINTF(1, 0);
extern JS_PUBLIC_API(JS::UniqueChars) JS_vsprintf_append(JS::UniqueChars&& last, extern JS_PUBLIC_API(JS::UniqueChars) JS_vsprintf_append(JS::UniqueChars&& last,
const char* fmt, va_list ap); const char* fmt, va_list ap)
MOZ_FORMAT_PRINTF(2, 0);
#endif /* jsprf_h */ #endif /* jsprf_h */

View file

@ -45,7 +45,7 @@ class GenericPrinter
// Prints a formatted string into the buffer. // Prints a formatted string into the buffer.
bool printf(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3); bool printf(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3);
bool vprintf(const char* fmt, va_list ap); bool vprintf(const char* fmt, va_list ap) MOZ_FORMAT_PRINTF(2, 0);
// Report that a string operation failed to get the memory it requested. The // Report that a string operation failed to get the memory it requested. The
// first call to this function calls JS_ReportOutOfMemory, and sets this // first call to this function calls JS_ReportOutOfMemory, and sets this

View file

@ -2268,7 +2268,7 @@ class MOZ_STACK_CLASS ModuleValidator
return failOffset(pn->pn_pos.begin, str); return failOffset(pn->pn_pos.begin, str);
} }
bool failfVAOffset(uint32_t offset, const char* fmt, va_list ap) { bool failfVAOffset(uint32_t offset, const char* fmt, va_list ap) MOZ_FORMAT_PRINTF(3, 0) {
MOZ_ASSERT(!hasAlreadyFailed()); MOZ_ASSERT(!hasAlreadyFailed());
MOZ_ASSERT(errorOffset_ == UINT32_MAX); MOZ_ASSERT(errorOffset_ == UINT32_MAX);
MOZ_ASSERT(fmt); MOZ_ASSERT(fmt);

View file

@ -627,6 +627,9 @@
* then the annotation would be: * then the annotation would be:
* MOZ_FORMAT_PRINTF(3, 4) * MOZ_FORMAT_PRINTF(3, 4)
* *
* The second argument should be 0 for vprintf-like functions; that
* is, those taking a va_list argument.
*
* Note that the checking is limited to standards-conforming * Note that the checking is limited to standards-conforming
* printf-likes, and in particular this should not be used for * printf-likes, and in particular this should not be used for
* PR_snprintf and friends, which are "printf-like" but which assign * PR_snprintf and friends, which are "printf-like" but which assign

View file

@ -18,6 +18,7 @@
#ifdef __cplusplus #ifdef __cplusplus
template <size_t N> template <size_t N>
MOZ_FORMAT_PRINTF(2, 0)
int VsprintfLiteral(char (&buffer)[N], const char* format, va_list args) int VsprintfLiteral(char (&buffer)[N], const char* format, va_list args)
{ {
MOZ_ASSERT(format != buffer); MOZ_ASSERT(format != buffer);

View file

@ -73,7 +73,7 @@ public:
bool MFBT_API print(const char* format, ...) MOZ_FORMAT_PRINTF(2, 3); bool MFBT_API print(const char* format, ...) MOZ_FORMAT_PRINTF(2, 3);
/* The Vprintf-like interface. */ /* The Vprintf-like interface. */
bool MFBT_API vprint(const char* format, va_list); bool MFBT_API vprint(const char* format, va_list) MOZ_FORMAT_PRINTF(2, 0);
protected: protected:
MFBT_API PrintfTarget(); MFBT_API PrintfTarget();
@ -140,7 +140,7 @@ class MOZ_STACK_CLASS SprintfState final : private mozilla::PrintfTarget, privat
this->free_(mBase); this->free_(mBase);
} }
bool vprint(const char* format, va_list ap_list) { bool vprint(const char* format, va_list ap_list) MOZ_FORMAT_PRINTF(2, 0) {
// The "" here has a single \0 character, which is what we're // The "" here has a single \0 character, which is what we're
// trying to append. // trying to append.
return mozilla::PrintfTarget::vprint(format, ap_list) && append("", 1); return mozilla::PrintfTarget::vprint(format, ap_list) && append("", 1);
@ -234,6 +234,7 @@ SmprintfPolicyPointer<AllocPolicy> SmprintfAppend(SmprintfPolicyPointer<AllocPol
** va_list forms of the above. ** va_list forms of the above.
*/ */
template<typename AllocPolicy = mozilla::MallocAllocPolicy> template<typename AllocPolicy = mozilla::MallocAllocPolicy>
MOZ_FORMAT_PRINTF(1, 0)
SmprintfPolicyPointer<AllocPolicy> Vsmprintf(const char* fmt, va_list ap) SmprintfPolicyPointer<AllocPolicy> Vsmprintf(const char* fmt, va_list ap)
{ {
SprintfState<AllocPolicy> ss(nullptr); SprintfState<AllocPolicy> ss(nullptr);
@ -243,6 +244,7 @@ SmprintfPolicyPointer<AllocPolicy> Vsmprintf(const char* fmt, va_list ap)
} }
template<typename AllocPolicy = mozilla::MallocAllocPolicy> template<typename AllocPolicy = mozilla::MallocAllocPolicy>
MOZ_FORMAT_PRINTF(2, 0)
SmprintfPolicyPointer<AllocPolicy> VsmprintfAppend(SmprintfPolicyPointer<AllocPolicy>&& last, SmprintfPolicyPointer<AllocPolicy> VsmprintfAppend(SmprintfPolicyPointer<AllocPolicy>&& last,
const char* fmt, va_list ap) const char* fmt, va_list ap)
{ {

View file

@ -346,6 +346,7 @@ public:
} }
void Print(const char* aName, LogLevel aLevel, const char* aFmt, va_list aArgs) void Print(const char* aName, LogLevel aLevel, const char* aFmt, va_list aArgs)
MOZ_FORMAT_PRINTF(4, 0)
{ {
const size_t kBuffSize = 1024; const size_t kBuffSize = 1024;
char buff[kBuffSize]; char buff[kBuffSize];

View file

@ -119,7 +119,7 @@ public:
/** /**
* Print a log message for this module. * Print a log message for this module.
*/ */
void Printv(LogLevel aLevel, const char* aFmt, va_list aArgs) const; void Printv(LogLevel aLevel, const char* aFmt, va_list aArgs) const MOZ_FORMAT_PRINTF(3, 0);
/** /**
* Retrieves the module name. * Retrieves the module name.

View file

@ -393,7 +393,7 @@ void printf_stderr(const char* aFmt, ...) MOZ_FORMAT_PRINTF(1, 2);
/** /**
* Same as printf_stderr, but taking va_list instead of varargs * Same as printf_stderr, but taking va_list instead of varargs
*/ */
void vprintf_stderr(const char* aFmt, va_list aArgs); void vprintf_stderr(const char* aFmt, va_list aArgs) MOZ_FORMAT_PRINTF(1, 0);
/** /**
* fprintf_stderr is like fprintf, except that if its file argument * fprintf_stderr is like fprintf, except that if its file argument

View file

@ -692,7 +692,7 @@ public:
* this with floating-point values as a result. * this with floating-point values as a result.
*/ */
void AppendPrintf(const char* aFormat, ...) MOZ_FORMAT_PRINTF(2, 3); void AppendPrintf(const char* aFormat, ...) MOZ_FORMAT_PRINTF(2, 3);
void AppendPrintf(const char* aFormat, va_list aAp); void AppendPrintf(const char* aFormat, va_list aAp) MOZ_FORMAT_PRINTF(2, 0);
void AppendInt(int32_t aInteger) void AppendInt(int32_t aInteger)
{ {
AppendPrintf("%" PRId32, aInteger); AppendPrintf("%" PRId32, aInteger);