aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Leung <daniel.leung@intel.com>2016-01-20 01:19:13 +0000
committerLisa Nguyen <lisa.nguyen@linaro.org>2016-02-23 16:51:57 -0800
commit1a53812d36050490cb847e2d6bfa05691e096f16 (patch)
tree104f88f8cde2591c4b8dca2929989eb70ce31136
parent06f7aa23641b8407202797ca6ff4a9fd1f67a216 (diff)
downloadpowertop-2.0-1a53812d36050490cb847e2d6bfa05691e096f16.tar.gz
Prevent seg faults in Android
The mbsrtowcs() in Android seems to change the content of source pointer to 0x00. So save a copy of the source string so we can manipulate it later, preventing segfaults. Signed-off-by: Daniel Leung <daniel.leung@linux.intel.com>
-rw-r--r--src/lib.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/lib.cpp b/src/lib.cpp
index 6c7f594..f65e447 100644
--- a/src/lib.cpp
+++ b/src/lib.cpp
@@ -278,6 +278,7 @@ string read_sysfs_string(const char *format, const char *param)
void align_string(char *buffer, size_t min_sz, size_t max_sz)
{
size_t sz;
+ char *buf = buffer;
/** mbsrtowcs() allows NULL dst and zero sz,
* comparing to mbstowcs(), which causes undefined
@@ -291,7 +292,7 @@ void align_string(char *buffer, size_t min_sz, size_t max_sz)
return;
}
while (sz < min_sz) {
- strcat(buffer, " ");
+ strcat(buf, " ");
sz++;
}
}