From 761b5c604568ef9b5db4eb3d73ba3053ef3f6d17 Mon Sep 17 00:00:00 2001
From: Zhaoyang Huang <zhaoyang.huang(a)linaro.org>
Date: Wed, 1 Jul 2015 15:22:01 +0800
Subject: [PATCH 1/2] prevent segment fault for android built 2
Hi powertop guys,
The bellowing patch is generated as the buffer within the function will
turn to be null in Android enviroment. I think maybe the reason should be
related to bionic libc.
the buffer will be turn into NULL after invoking the mbsrtowcs function
of bionic libc. Add a condition judgement for that
Signed-off-by: Zhaoyang Huang <zhaoyang.huang(a)linaro.org>
---
src/lib.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lib.cpp b/src/lib.cpp
index 88fe5f3..8d1ca9f 100644
--- a/src/lib.cpp
+++ b/src/lib.cpp
@@ -285,7 +285,7 @@ void align_string(char *buffer, size_t min_sz, size_t max_sz)
/* start with mbsrtowcs() local mbstate_t * and
* NULL dst pointer*/
sz = mbsrtowcs(NULL, (const char **)&buffer, max_sz, NULL);
- if (sz == (size_t)-1) {
+ if ((sz == (size_t)-1) && (NULL != buffer)) {
buffer[min_sz] = 0x00;
return;
}
--
1.7.9.5