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
Родитель 8fef752ced
Коммит aa6e054b71
16 изменённых файлов: 28 добавлений и 18 удалений

Просмотреть файл

@ -2054,7 +2054,7 @@ protected:
public:
// console logging helpers
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);

Просмотреть файл

@ -183,9 +183,9 @@ void JitSpewCont(JitSpewChannel channel, const char* fmt, ...) MOZ_FORMAT_PRINTF
void JitSpewFin(JitSpewChannel channel);
void JitSpewHeader(JitSpewChannel channel);
bool JitSpewEnabled(JitSpewChannel channel);
void JitSpewVA(JitSpewChannel channel, const char* fmt, va_list ap);
void JitSpewStartVA(JitSpewChannel channel, const char* fmt, va_list ap);
void JitSpewContVA(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) MOZ_FORMAT_PRINTF(2, 0);
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 EnableChannel(JitSpewChannel channel);
@ -253,7 +253,8 @@ static inline void JitSpewHeader(JitSpewChannel channel)
{ }
static inline bool JitSpewEnabled(JitSpewChannel channel)
{ 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)
{ }

Просмотреть файл

@ -77,7 +77,7 @@ class MIRGenerator
abort(AbortReason r, const char* message, ...) MOZ_FORMAT_PRINTF(3, 4);
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
// off-thread compilation can report what error got encountered.

Просмотреть файл

@ -1317,7 +1317,7 @@ class Assembler : public AssemblerShared
uint32_t spewProbe(Label* l);
uint32_t spewDefine(Label* l);
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
public:

Просмотреть файл

@ -223,7 +223,7 @@ namespace jit {
}
#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
};

Просмотреть файл

@ -1024,7 +1024,7 @@ SelfHostedFunction(JSContext* cx, HandlePropertyName propName);
#ifdef va_start
extern bool
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
ReportErrorNumberVA(JSContext* cx, unsigned flags, JSErrorCallback callback,

Просмотреть файл

@ -26,8 +26,10 @@ extern JS_PUBLIC_API(JS::UniqueChars) JS_sprintf_append(JS::UniqueChars&& last,
const char* fmt, ...)
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,
const char* fmt, va_list ap);
const char* fmt, va_list ap)
MOZ_FORMAT_PRINTF(2, 0);
#endif /* jsprf_h */

Просмотреть файл

@ -45,7 +45,7 @@ class GenericPrinter
// Prints a formatted string into the buffer.
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
// first call to this function calls JS_ReportOutOfMemory, and sets this

Просмотреть файл

@ -2268,7 +2268,7 @@ class MOZ_STACK_CLASS ModuleValidator
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(errorOffset_ == UINT32_MAX);
MOZ_ASSERT(fmt);

Просмотреть файл

@ -627,6 +627,9 @@
* then the annotation would be:
* 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
* printf-likes, and in particular this should not be used for
* PR_snprintf and friends, which are "printf-like" but which assign

Просмотреть файл

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

Просмотреть файл

@ -73,7 +73,7 @@ public:
bool MFBT_API print(const char* format, ...) MOZ_FORMAT_PRINTF(2, 3);
/* 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:
MFBT_API PrintfTarget();
@ -140,7 +140,7 @@ class MOZ_STACK_CLASS SprintfState final : private mozilla::PrintfTarget, privat
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
// trying to append.
return mozilla::PrintfTarget::vprint(format, ap_list) && append("", 1);
@ -234,6 +234,7 @@ SmprintfPolicyPointer<AllocPolicy> SmprintfAppend(SmprintfPolicyPointer<AllocPol
** va_list forms of the above.
*/
template<typename AllocPolicy = mozilla::MallocAllocPolicy>
MOZ_FORMAT_PRINTF(1, 0)
SmprintfPolicyPointer<AllocPolicy> Vsmprintf(const char* fmt, va_list ap)
{
SprintfState<AllocPolicy> ss(nullptr);
@ -243,6 +244,7 @@ SmprintfPolicyPointer<AllocPolicy> Vsmprintf(const char* fmt, va_list ap)
}
template<typename AllocPolicy = mozilla::MallocAllocPolicy>
MOZ_FORMAT_PRINTF(2, 0)
SmprintfPolicyPointer<AllocPolicy> VsmprintfAppend(SmprintfPolicyPointer<AllocPolicy>&& last,
const char* fmt, va_list ap)
{

Просмотреть файл

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

Просмотреть файл

@ -119,7 +119,7 @@ public:
/**
* 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.

Просмотреть файл

@ -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
*/
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

Просмотреть файл

@ -692,7 +692,7 @@ public:
* this with floating-point values as a result.
*/
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)
{
AppendPrintf("%" PRId32, aInteger);