Skip to content

Commit

Permalink
Bug 1334279 - mark vsprintf-likes with MOZ_FORMAT_PRINTF; r=froydnj
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tromey committed May 4, 2017
1 parent d620ccd commit 8e13b1c
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dom/canvas/WebGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@ class WebGLContext
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);

Expand Down
9 changes: 5 additions & 4 deletions js/src/jit/JitSpewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{ }
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/MIRGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/arm/Assembler-arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
2 changes: 1 addition & 1 deletion js/src/jscntxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions js/src/jsprf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 1 addition & 1 deletion js/src/vm/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion js/src/wasm/AsmJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions mfbt/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mfbt/Sprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions mozglue/misc/Printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PrintfTarget
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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions xpcom/base/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class LogModuleManager
}

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];
Expand Down
2 changes: 1 addition & 1 deletion xpcom/base/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class LogModule
/**
* 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.
Expand Down
2 changes: 1 addition & 1 deletion xpcom/base/nsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xpcom/string/nsTSubstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ class nsTSubstring_CharT : public mozilla::detail::nsTStringRepr_CharT
* 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);
Expand Down

0 comments on commit 8e13b1c

Please sign in to comment.