Created constant for maximun number of args.
BUG: 26379932
Change-Id: I839f6e3f90010ee35bc5d40e96218e9c95afdf4e
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index a4ef686..0d8a0ea 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -278,11 +278,12 @@
std::string timeout_string = std::to_string(timeout_seconds);
- const char *dumpsys_args[ARG_MAX] = { "/system/bin/dumpsys", "-t", timeout_string.c_str()};
+ const char *dumpsys_args[MAX_ARGS_ARRAY_SIZE] =
+ { "/system/bin/dumpsys", "-t", timeout_string.c_str()};
int index = 3; // 'dumpsys' '-t' 'TIMEOUT'
for (const std::string& arg : args) {
- if (index > ARG_MAX - 2) {
+ if (index > MAX_ARGS_ARRAY_SIZE - 2) {
MYLOGE("Too many arguments for '%s': %d\n", title.c_str(), (int) args.size());
return;
}
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 0b87368..2dddda0 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -37,6 +37,11 @@
#define SU_PATH "/system/xbin/su"
+// Workaround for const char *args[MAX_ARGS_ARRAY_SIZE] variables until they're converted to
+// std::vector<std::string>
+#define MAX_ARGS_ARRAY_SIZE 1000
+
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index 4076f6a..3e4d343 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -655,7 +655,7 @@
DurationReporter duration_reporter(title);
fflush(stdout);
- const char *args[ARG_MAX] = {command};
+ const char *args[MAX_ARGS_ARRAY_SIZE] = {command};
size_t arg;
va_list ap;
va_start(ap, command);
@@ -696,7 +696,7 @@
DurationReporter duration_reporter(title);
fflush(stdout);
- const char *args[ARG_MAX] = {command};
+ const char *args[MAX_ARGS_ARRAY_SIZE] = {command};
size_t arg;
va_list ap;
va_start(ap, command);
@@ -888,11 +888,11 @@
MYLOGE("send_broadcast: too many arguments (%d)\n", (int) args.size());
return;
}
- const char *am_args[ARG_MAX] = { "/system/bin/am", "broadcast", "--user", "0", "-a",
+ const char *am_args[MAX_ARGS_ARRAY_SIZE] = { "/system/bin/am", "broadcast", "--user", "0", "-a",
action.c_str() };
size_t am_index = 5; // Starts at the index of last initial value above.
for (const std::string& arg : args) {
- if (am_index > ARG_MAX - 2) {
+ if (am_index > MAX_ARGS_ARRAY_SIZE - 2) {
MYLOGE("send_broadcast: too many arguments (%d)\n", (int) args.size());
return;
}
@@ -1416,7 +1416,7 @@
if (args[1] == nullptr) return;
string->append(" ");
- for (int arg = 1; arg <= 1000; ++arg) {
+ for (int arg = 1; arg <= MAX_ARGS_ARRAY_SIZE; ++arg) {
if (args[arg] == nullptr) return;
string->append(args[arg]);
if (args[arg+1] != nullptr) {