Turn on -Wformat-nonliteral.
Apparently there are two classes of this warning in clang.
-Wformat-security is only emitted for cases of
`func(nonliteral_fmt_string)` (no args), and -Wformat-nonliteral is
emitted for cases *with* arguments. For whatever reason, the latter
isn't included in -Wextra and must be manually enabled.
To make this more easily portable to Windows, move the existing
gnu_printf/__printf__ decision into base/macros.h as ATTRIBUTE_FORMAT.
Change-Id: I3b0990e1d1f0a2e9c13b32f5cd60478946cb5fc6
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index 4adac37..59e0807 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -1447,7 +1447,8 @@
return pm_command(transport, serial, argc, argv);
}
-static int delete_file(TransportType transport, const char* serial, char* filename) {
+static int delete_file(TransportType transport, const char* serial,
+ const char* filename) {
std::string cmd = "shell:rm -f " + escape_arg(filename);
return send_shell_command(transport, serial, cmd);
}
@@ -1464,8 +1465,8 @@
}
static int install_app(TransportType transport, const char* serial, int argc, const char** argv) {
- static const char *const DATA_DEST = "/data/local/tmp/%s";
- static const char *const SD_DEST = "/sdcard/tmp/%s";
+ static const char *const DATA_DEST = "/data/local/tmp";
+ static const char *const SD_DEST = "/sdcard/tmp";
const char* where = DATA_DEST;
int i;
struct stat sb;
@@ -1499,19 +1500,20 @@
}
const char* apk_file = argv[last_apk];
- char apk_dest[PATH_MAX];
- snprintf(apk_dest, sizeof apk_dest, where, get_basename(apk_file));
- int err = do_sync_push(apk_file, apk_dest, 0 /* no show progress */);
+ const std::string apk_dest =
+ android::base::StringPrintf("%s/%s", where, get_basename(apk_file));
+ int err = do_sync_push(apk_file, apk_dest.c_str(), /* show_progress = */ 0);
if (err) {
goto cleanup_apk;
} else {
- argv[last_apk] = apk_dest; /* destination name, not source location */
+ // Destination name, not source location.
+ argv[last_apk] = apk_dest.c_str();
}
err = pm_command(transport, serial, argc, argv);
cleanup_apk:
- delete_file(transport, serial, apk_dest);
+ delete_file(transport, serial, apk_dest.c_str());
return err;
}