Changeset 1040 for cpp/frams/util
- Timestamp:
- 11/30/20 04:32:21 (4 years ago)
- Location:
- cpp/frams/util
- Files:
-
- 2 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 -
cpp/frams/util/sstring.cpp
r996 r1040 417 417 if (n < 0 && size >= (1 << 24)) //wants more than 16M 418 418 { 419 buf[size - 1] = 0; //just to ensure there is at least some ending \0 in memory... who knows what buggy vsnprintf() did.420 __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);419 p[size - 1] = 0; //just to ensure there is at least some ending \0 in memory... who knows what buggy vsnprintf() did. 420 __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); 421 421 //in my tests, it always used 0 bytes, so it produced a 0-length string: "" 422 va_ copy(ap_copy, ap);423 n = vs printf(buf, format, ap_copy); //hoping 16M is enough424 va_end(ap _copy);425 __android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, "Fallback to vsprintf() produced string: '%s'", buf);422 va_start(ap, format); 423 n = vsnprintf(p, size, format, ap); //hoping 16M is enough 424 va_end(ap); 425 __android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, "Fallback to vsprintf() produced string: '%s'", p); 426 426 if (n < 0) //vsprintf was also buggy. If we were strict, we should abort the app now. 427 427 { 428 strcpy( buf, "[STR_ERR] "); //a special prefix just to indicate the returned string is incorrect429 strcat( buf, format); //append and return the original formatting string430 __android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "vsprintf() also failed, using the incorrect resulting string: '%s'", buf);428 strcpy(p, "[STR_ERR] "); //a special prefix just to indicate the returned string is incorrect 429 strcat(p, format); //append and return the original formatting string 430 __android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, "vsprintf() also failed, using the incorrect resulting string: '%s'", p); 431 431 } 432 n = strlen( buf); //pretend vsnprintf() or vsprintf() was OK to exit the endless loop432 n = strlen(p); //pretend vsnprintf() or vsprintf() was OK to exit the endless loop 433 433 } 434 434 #endif
Note: See TracChangeset
for help on using the changeset viewer.