Index: cpp/frams/util/sstring-simple.cpp
===================================================================
--- cpp/frams/util/sstring-simple.cpp	(revision 1022)
+++ cpp/frams/util/sstring-simple.cpp	(revision 1040)
@@ -4,4 +4,8 @@
 #include <assert.h>
 #include <common/nonstd_math.h>
+
+#ifdef __ANDROID__
+#include <android/log.h> //only needed to print error messages related to a workaround for Android bug
+#endif
 
 
@@ -273,18 +277,18 @@
 		if (n < 0 && size >= (1 << 24)) //wants more than 16M
 		{
-			buf[size - 1] = 0; //just to ensure there is at least some ending \0 in memory... who knows what buggy vsnprintf() did.
-			__android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "Giving up due to Android bug: vsnprintf() wants more than %d bytes, it used %zu bytes, for format='%s'", size, strlen(buf), format);
+			p[size - 1] = 0; //just to ensure there is at least some ending \0 in memory... who knows what buggy vsnprintf() did.
+			__android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "Giving up due to Android bug: vsnprintf() wants more than %d bytes, it used %zu bytes, for format='%s'", size, strlen(p), format);
 			//in my tests, it always used 0 bytes, so it produced a 0-length string: ""
-			va_copy(ap_copy, ap);
-			n = vsprintf(buf, format, ap_copy); //hoping 16M is enough
-			va_end(ap_copy);
-			__android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, "Fallback to vsprintf() produced string: '%s'", buf);
+			va_start(ap, format);
+			n = vsnprintf(p, size, format, ap); //hoping 16M is enough
+			va_end(ap);
+			__android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, "Fallback to vsprintf() produced string: '%s'", p);
 			if (n < 0) //vsprintf was also buggy. If we were strict, we should abort the app now.
 			{
-				strcpy(buf, "[STR_ERR] "); //a special prefix just to indicate the returned string is incorrect
-				strcat(buf, format); //append and return the original formatting string
-				__android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "vsprintf() also failed, using the incorrect resulting string: '%s'", buf);
+				strcpy(p, "[STR_ERR] "); //a special prefix just to indicate the returned string is incorrect
+				strcat(p, format); //append and return the original formatting string
+				__android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "vsprintf() also failed, using the incorrect resulting string: '%s'", p);
 			}
-			n = strlen(buf); //pretend vsnprintf() or vsprintf() was OK to exit the endless loop
+			n = strlen(p); //pretend vsnprintf() or vsprintf() was OK to exit the endless loop
 	}
 #endif
Index: cpp/frams/util/sstring.cpp
===================================================================
--- cpp/frams/util/sstring.cpp	(revision 1022)
+++ cpp/frams/util/sstring.cpp	(revision 1040)
@@ -417,18 +417,18 @@
 		if (n < 0 && size >= (1 << 24)) //wants more than 16M
 		{
-			buf[size - 1] = 0; //just to ensure there is at least some ending \0 in memory... who knows what buggy vsnprintf() did.
-			__android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "Giving up due to Android bug: vsnprintf() wants more than %d bytes, it used %zu bytes, for format='%s'", size, strlen(buf), format);
+			p[size - 1] = 0; //just to ensure there is at least some ending \0 in memory... who knows what buggy vsnprintf() did.
+			__android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "Giving up due to Android bug: vsnprintf() wants more than %d bytes, it used %zu bytes, for format='%s'", size, strlen(p), format);
 			//in my tests, it always used 0 bytes, so it produced a 0-length string: ""
-			va_copy(ap_copy, ap);
-			n = vsprintf(buf, format, ap_copy); //hoping 16M is enough
-			va_end(ap_copy);
-			__android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, "Fallback to vsprintf() produced string: '%s'", buf);
+			va_start(ap, format);
+			n = vsnprintf(p, size, format, ap); //hoping 16M is enough
+			va_end(ap);
+			__android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, "Fallback to vsprintf() produced string: '%s'", p);
 			if (n < 0) //vsprintf was also buggy. If we were strict, we should abort the app now.
 			{
-				strcpy(buf, "[STR_ERR] "); //a special prefix just to indicate the returned string is incorrect
-				strcat(buf, format); //append and return the original formatting string
-				__android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "vsprintf() also failed, using the incorrect resulting string: '%s'", buf);
+				strcpy(p, "[STR_ERR] "); //a special prefix just to indicate the returned string is incorrect
+				strcat(p, format); //append and return the original formatting string
+				__android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "vsprintf() also failed, using the incorrect resulting string: '%s'", p);
 			}
-			n = strlen(buf); //pretend vsnprintf() or vsprintf() was OK to exit the endless loop
+			n = strlen(p); //pretend vsnprintf() or vsprintf() was OK to exit the endless loop
 		}
 #endif
