Use -Werror in frameworks/base
* Fix unused variable and return value warnings.
Bug: 66996870
Test: build with WITH_TIDY=1
Change-Id: I890e65a20848d00559ba5a4f9691be1347b456af
diff --git a/tools/bit/Android.bp b/tools/bit/Android.bp
index 258e9b5..a806271 100644
--- a/tools/bit/Android.bp
+++ b/tools/bit/Android.bp
@@ -30,6 +30,11 @@
"util.cpp",
],
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+
static_libs: [
"libexpat",
"libinstrumentation",
diff --git a/tools/bit/adb.cpp b/tools/bit/adb.cpp
index 0c8424d..93fda54 100644
--- a/tools/bit/adb.cpp
+++ b/tools/bit/adb.cpp
@@ -293,7 +293,9 @@
print_command(cmd);
int fds[2];
- pipe(fds);
+ if (0 != pipe(fds)) {
+ return errno;
+ }
pid_t pid = fork();
diff --git a/tools/bit/command.cpp b/tools/bit/command.cpp
index 9a8449b..1ff7c22 100644
--- a/tools/bit/command.cpp
+++ b/tools/bit/command.cpp
@@ -105,7 +105,9 @@
}
int fds[2];
- pipe(fds);
+ if (0 != pipe(fds)) {
+ return string();
+ }
pid_t pid = fork();
diff --git a/tools/bit/main.cpp b/tools/bit/main.cpp
index d056ba5..ad23971 100644
--- a/tools/bit/main.cpp
+++ b/tools/bit/main.cpp
@@ -561,6 +561,15 @@
}
}
+static void
+chdir_or_exit(const char *path) {
+ // TODO: print_command("cd", path);
+ if (0 != chdir(path)) {
+ print_error("Error: Could not chdir: %s", path);
+ exit(1);
+ }
+}
+
/**
* Run the build, install, and test actions.
*/
@@ -583,8 +592,7 @@
const string buildId = get_build_var(buildTop, "BUILD_ID", false);
const string buildOut = get_out_dir();
- // TODO: print_command("cd", buildTop.c_str());
- chdir(buildTop.c_str());
+ chdir_or_exit(buildTop.c_str());
// Get the modules for the targets
map<string,Module> modules;
@@ -952,7 +960,7 @@
const string buildProduct = get_required_env("TARGET_PRODUCT", false);
const string buildOut = get_out_dir();
- chdir(buildTop.c_str());
+ chdir_or_exit(buildTop.c_str());
string buildDevice = sniff_device_name(buildOut, buildProduct);
diff --git a/tools/bit/util.cpp b/tools/bit/util.cpp
index fc93bcb..9223931 100644
--- a/tools/bit/util.cpp
+++ b/tools/bit/util.cpp
@@ -101,7 +101,6 @@
void
get_directory_contents(const string& name, map<string,FileInfo>* results)
{
- int err;
DIR* dir = opendir(name.c_str());
if (dir == NULL) {
return;
@@ -241,7 +240,9 @@
fseek(file, 0, SEEK_SET);
char* buf = (char*)malloc(size);
- fread(buf, 1, size, file);
+ if ((size_t) size != fread(buf, 1, size, file)) {
+ return string();
+ }
string result(buf, size);
diff --git a/tools/incident_report/Android.bp b/tools/incident_report/Android.bp
index ab55dbd..f2d0d0f 100644
--- a/tools/incident_report/Android.bp
+++ b/tools/incident_report/Android.bp
@@ -31,5 +31,5 @@
"libprotobuf-cpp-full",
],
- cflags: ["-Wno-unused-parameter"],
+ cflags: ["-Wall", "-Werror"],
}
diff --git a/tools/incident_report/printer.cpp b/tools/incident_report/printer.cpp
index bd660dd2..bff1025 100644
--- a/tools/incident_report/printer.cpp
+++ b/tools/incident_report/printer.cpp
@@ -70,7 +70,6 @@
len = vsnprintf(mBuf, mBufSize, format, args);
va_end(args);
- bool truncated = (len >= mBufSize) && (reallocate(len) < len);
va_start(args, format);
len = vsnprintf(mBuf, mBufSize, format, args);
diff --git a/tools/incident_section_gen/Android.bp b/tools/incident_section_gen/Android.bp
index 1756e06..f07445a 100644
--- a/tools/incident_section_gen/Android.bp
+++ b/tools/incident_section_gen/Android.bp
@@ -22,6 +22,8 @@
cflags: [
"-g",
"-O0",
+ "-Wall",
+ "-Werror",
],
srcs: ["main.cpp"],
shared_libs: [