Merge "Simplify __attribute__((__printf__)) use."

This commit is contained in:
Treehugger Robot 2018-06-26 23:58:09 +00:00 committed by Gerrit Code Review
commit 2aa50ff56d
6 changed files with 17 additions and 34 deletions

View file

@ -124,8 +124,6 @@ inline bool ConnectionStateIsOnline(ConnectionState state) {
void print_packet(const char* label, apacket* p); void print_packet(const char* label, apacket* p);
// These use the system (v)fprintf, not the adb prefixed ones defined in sysdeps.h, so they
// shouldn't be tagged with ADB_FORMAT_ARCHETYPE.
void fatal(const char* fmt, ...) __attribute__((noreturn, format(__printf__, 1, 2))); void fatal(const char* fmt, ...) __attribute__((noreturn, format(__printf__, 1, 2)));
void fatal_errno(const char* fmt, ...) __attribute__((noreturn, format(__printf__, 1, 2))); void fatal_errno(const char* fmt, ...) __attribute__((noreturn, format(__printf__, 1, 2)));

View file

@ -510,8 +510,7 @@ class SyncConnection {
return false; return false;
} }
void Printf(const char* fmt, ...) __attribute__((__format__(__printf__, 2, 3))) {
void Printf(const char* fmt, ...) __attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 3))) {
std::string s; std::string s;
va_list ap; va_list ap;
@ -522,7 +521,7 @@ class SyncConnection {
line_printer_.Print(s, LinePrinter::INFO); line_printer_.Print(s, LinePrinter::INFO);
} }
void Println(const char* fmt, ...) __attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 3))) { void Println(const char* fmt, ...) __attribute__((__format__(__printf__, 2, 3))) {
std::string s; std::string s;
va_list ap; va_list ap;
@ -534,7 +533,7 @@ class SyncConnection {
line_printer_.KeepInfoLine(); line_printer_.KeepInfoLine();
} }
void Error(const char* fmt, ...) __attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 3))) { void Error(const char* fmt, ...) __attribute__((__format__(__printf__, 2, 3))) {
std::string s = "adb: error: "; std::string s = "adb: error: ";
va_list ap; va_list ap;
@ -545,7 +544,7 @@ class SyncConnection {
line_printer_.Print(s, LinePrinter::ERROR); line_printer_.Print(s, LinePrinter::ERROR);
} }
void Warning(const char* fmt, ...) __attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 3))) { void Warning(const char* fmt, ...) __attribute__((__format__(__printf__, 2, 3))) {
std::string s = "adb: warning: "; std::string s = "adb: warning: ";
va_list ap; va_list ap;

View file

@ -39,11 +39,6 @@
#include "sysdeps/network.h" #include "sysdeps/network.h"
#include "sysdeps/stat.h" #include "sysdeps/stat.h"
// Some printf-like functions are implemented in terms of
// android::base::StringAppendV, so they should use the same attribute for
// compile-time format string checking.
#define ADB_FORMAT_ARCHETYPE __printf__
#ifdef _WIN32 #ifdef _WIN32
// Clang-only nullability specifiers // Clang-only nullability specifiers
@ -204,14 +199,12 @@ extern int adb_closedir(DIR* dir);
extern int adb_utime(const char *, struct utimbuf *); extern int adb_utime(const char *, struct utimbuf *);
extern int adb_chmod(const char *, int); extern int adb_chmod(const char *, int);
extern int adb_vfprintf(FILE *stream, const char *format, va_list ap) extern int adb_vfprintf(FILE* stream, const char* format, va_list ap)
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 0))); __attribute__((__format__(__printf__, 2, 0)));
extern int adb_vprintf(const char *format, va_list ap) extern int adb_vprintf(const char* format, va_list ap) __attribute__((__format__(__printf__, 1, 0)));
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 1, 0))); extern int adb_fprintf(FILE* stream, const char* format, ...)
extern int adb_fprintf(FILE *stream, const char *format, ...) __attribute__((__format__(__printf__, 2, 3)));
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 3))); extern int adb_printf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2)));
extern int adb_printf(const char *format, ...)
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 1, 2)));
extern int adb_fputs(const char* buf, FILE* stream); extern int adb_fputs(const char* buf, FILE* stream);
extern int adb_fputc(int ch, FILE* stream); extern int adb_fputc(int ch, FILE* stream);

View file

@ -2455,9 +2455,8 @@ static int _console_write_utf8(const char* const buf, const size_t buf_size, FIL
} }
// Function prototype because attributes cannot be placed on func definitions. // Function prototype because attributes cannot be placed on func definitions.
static int _console_vfprintf(const HANDLE console, FILE* stream, static int _console_vfprintf(const HANDLE console, FILE* stream, const char* format, va_list ap)
const char *format, va_list ap) __attribute__((__format__(__printf__, 3, 0)));
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 3, 0)));
// Internal function to format a UTF-8 string and write it to a Win32 console. // Internal function to format a UTF-8 string and write it to a Win32 console.
// Returns -1 on error. // Returns -1 on error.

View file

@ -25,21 +25,17 @@ namespace base {
// These printf-like functions are implemented in terms of vsnprintf, so they // These printf-like functions are implemented in terms of vsnprintf, so they
// use the same attribute for compile-time format string checking. // use the same attribute for compile-time format string checking.
#define ANDROID_BASE_FORMAT_ARCHETYPE __printf__
// Returns a string corresponding to printf-like formatting of the arguments. // Returns a string corresponding to printf-like formatting of the arguments.
std::string StringPrintf(const char* fmt, ...) std::string StringPrintf(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
__attribute__((__format__(ANDROID_BASE_FORMAT_ARCHETYPE, 1, 2)));
// Appends a printf-like formatting of the arguments to 'dst'. // Appends a printf-like formatting of the arguments to 'dst'.
void StringAppendF(std::string* dst, const char* fmt, ...) void StringAppendF(std::string* dst, const char* fmt, ...)
__attribute__((__format__(ANDROID_BASE_FORMAT_ARCHETYPE, 2, 3))); __attribute__((__format__(__printf__, 2, 3)));
// Appends a printf-like formatting of the arguments to 'dst'. // Appends a printf-like formatting of the arguments to 'dst'.
void StringAppendV(std::string* dst, const char* format, va_list ap) void StringAppendV(std::string* dst, const char* format, va_list ap)
__attribute__((__format__(ANDROID_BASE_FORMAT_ARCHETYPE, 2, 0))); __attribute__((__format__(__printf__, 2, 0)));
#undef ANDROID_BASE_FORMAT_ARCHETYPE
} // namespace base } // namespace base
} // namespace android } // namespace android

View file

@ -79,11 +79,9 @@ void set_verbose();
// These printf-like functions are implemented in terms of vsnprintf, so they // These printf-like functions are implemented in terms of vsnprintf, so they
// use the same attribute for compile-time format string checking. // use the same attribute for compile-time format string checking.
#define FASTBOOT_FORMAT_ARCHETYPE __printf__
void die(const char* fmt, ...) __attribute__((__noreturn__)) void die(const char* fmt, ...) __attribute__((__noreturn__))
__attribute__((__format__(FASTBOOT_FORMAT_ARCHETYPE, 1, 2))); __attribute__((__format__(__printf__, 1, 2)));
void verbose(const char* fmt, ...) __attribute__((__format__(FASTBOOT_FORMAT_ARCHETYPE, 1, 2))); void verbose(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
#undef FASTBOOT_FORMAT_ARCHETYPE
/* Current product */ /* Current product */
extern char cur_product[FB_RESPONSE_SZ + 1]; extern char cur_product[FB_RESPONSE_SZ + 1];