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-08-08 11:14:40 -0700
commit74149cbbcf20f9d2830cf57fc2c64fdc8a2e3b8e (patch)
tree1fe7a2d9852106ff7630294565c5cd5f4f88a68f
parentc73e386654a823e228abcd4647416839e60fed67 (diff)
downloadpowertop-2.0-74149cbbcf20f9d2830cf57fc2c64fdc8a2e3b8e.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. This fix by Daniel resolves this bug: https://bugs.linaro.org/show_bug.cgi?id=1273 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 9521415..e1ab0b9 100644
--- a/src/lib.cpp
+++ b/src/lib.cpp
@@ -279,6 +279,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
@@ -292,7 +293,7 @@ void align_string(char *buffer, size_t min_sz, size_t max_sz)
return;
}
while (sz < min_sz) {
- strcat(buffer, " ");
+ strcat(buf, " ");
sz++;
}
}