Changeset 1040 for cpp/frams/util/sstring-simple.cpp
- Timestamp:
- 11/30/20 04:32:21 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/sstring-simple.cpp
r996 r1040 4 4 #include <assert.h> 5 5 #include <common/nonstd_math.h> 6 7 #ifdef __ANDROID__ 8 #include <android/log.h> //only needed to print error messages related to a workaround for Android bug 9 #endif 6 10 7 11 … … 273 277 if (n < 0 && size >= (1 << 24)) //wants more than 16M 274 278 { 275 buf[size - 1] = 0; //just to ensure there is at least some ending \0 in memory... who knows what buggy vsnprintf() did.276 __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);279 p[size - 1] = 0; //just to ensure there is at least some ending \0 in memory... who knows what buggy vsnprintf() did. 280 __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); 277 281 //in my tests, it always used 0 bytes, so it produced a 0-length string: "" 278 va_ copy(ap_copy, ap);279 n = vs printf(buf, format, ap_copy); //hoping 16M is enough280 va_end(ap _copy);281 __android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, "Fallback to vsprintf() produced string: '%s'", buf);282 va_start(ap, format); 283 n = vsnprintf(p, size, format, ap); //hoping 16M is enough 284 va_end(ap); 285 __android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, "Fallback to vsprintf() produced string: '%s'", p); 282 286 if (n < 0) //vsprintf was also buggy. If we were strict, we should abort the app now. 283 287 { 284 strcpy( buf, "[STR_ERR] "); //a special prefix just to indicate the returned string is incorrect285 strcat( buf, format); //append and return the original formatting string286 __android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "vsprintf() also failed, using the incorrect resulting string: '%s'", buf);288 strcpy(p, "[STR_ERR] "); //a special prefix just to indicate the returned string is incorrect 289 strcat(p, format); //append and return the original formatting string 290 __android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "vsprintf() also failed, using the incorrect resulting string: '%s'", p); 287 291 } 288 n = strlen( buf); //pretend vsnprintf() or vsprintf() was OK to exit the endless loop292 n = strlen(p); //pretend vsnprintf() or vsprintf() was OK to exit the endless loop 289 293 } 290 294 #endif
Note: See TracChangeset
for help on using the changeset viewer.