Changeset 1040 for cpp/frams/util/sstring.cpp
- Timestamp:
- 11/30/20 04:32:21 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.