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);
// 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_errno(const char* fmt, ...) __attribute__((noreturn, format(__printf__, 1, 2)));

View file

@ -510,8 +510,7 @@ class SyncConnection {
return false;
}
void Printf(const char* fmt, ...) __attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 3))) {
void Printf(const char* fmt, ...) __attribute__((__format__(__printf__, 2, 3))) {
std::string s;
va_list ap;
@ -522,7 +521,7 @@ class SyncConnection {
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;
va_list ap;
@ -534,7 +533,7 @@ class SyncConnection {
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: ";
va_list ap;
@ -545,7 +544,7 @@ class SyncConnection {
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: ";
va_list ap;

View file

@ -39,11 +39,6 @@
#include "sysdeps/network.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
// 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_chmod(const char *, int);
extern int adb_vfprintf(FILE *stream, const char *format, va_list ap)
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 0)));
extern int adb_vprintf(const char *format, va_list ap)
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 1, 0)));
extern int adb_fprintf(FILE *stream, const char *format, ...)
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 3)));
extern int adb_printf(const char *format, ...)
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 1, 2)));
extern int adb_vfprintf(FILE* stream, const char* format, va_list ap)
__attribute__((__format__(__printf__, 2, 0)));
extern int adb_vprintf(const char* format, va_list ap) __attribute__((__format__(__printf__, 1, 0)));
extern int adb_fprintf(FILE* stream, const char* format, ...)
__attribute__((__format__(__printf__, 2, 3)));
extern int adb_printf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2)));
extern int adb_fputs(const char* buf, 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.
static int _console_vfprintf(const HANDLE console, FILE* stream,
const char *format, va_list ap)
__attribute__((__format__(ADB_FORMAT_ARCHETYPE, 3, 0)));
static int _console_vfprintf(const HANDLE console, FILE* stream, const char* format, va_list ap)
__attribute__((__format__(__printf__, 3, 0)));
// Internal function to format a UTF-8 string and write it to a Win32 console.
// Returns -1 on error.

View file

@ -25,21 +25,17 @@ namespace base {
// These printf-like functions are implemented in terms of vsnprintf, so they
// 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.
std::string StringPrintf(const char* fmt, ...)
__attribute__((__format__(ANDROID_BASE_FORMAT_ARCHETYPE, 1, 2)));
std::string StringPrintf(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
// Appends a printf-like formatting of the arguments to 'dst'.
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'.
void StringAppendV(std::string* dst, const char* format, va_list ap)
__attribute__((__format__(ANDROID_BASE_FORMAT_ARCHETYPE, 2, 0)));
#undef ANDROID_BASE_FORMAT_ARCHETYPE
__attribute__((__format__(__printf__, 2, 0)));
} // namespace base
} // namespace android

View file

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