morningman opened a new issue #1018: FloatToBuffer may core in some case URL: https://github.com/apache/incubator-doris/issues/1018 **Describe the bug** in `src/gutil/strings/numbers.cc` ``` 1310 int FloatToBuffer(float value, int width, char *buffer) { 1311 // FLT_DIG is 6 for IEEE-754 floats, which are used on almost all 1312 // platforms these days. Just in case some system exists where FLT_DIG 1313 // is significantly larger -- and risks overflowing our buffer -- we have 1314 // this assert. 1315 COMPILE_ASSERT(FLT_DIG < 10, FLT_DIG_is_too_big); 1316 1317 int snprintf_result = 1318 snprintf(buffer, width, "%.*g", FLT_DIG, value); 1319 1320 // The snprintf should never overflow because the buffer is significantly 1321 // larger than the precision we asked for. 1322 DCHECK(snprintf_result > 0 && snprintf_result < width); 1323 1324 float parsed_value; 1325 if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) { 1326 snprintf_result = 1327 snprintf(buffer, width, "%.*g", FLT_DIG+2, value); 1328 1329 // Should never overflow; see above. 1330 DCHECK(snprintf_result > 0 && snprintf_result < width); 1331 } 1332 1333 return snprintf_result; 1334 } ``` line 1325: `parsed_value != value` may return true even if 2 values are some(because they are float) after line 1327, the snprintf_result = 14, which equal to width, such causing DCHECK failed. In gutils, the width here is 24, far larger than 14. So we just increase the width value to avoid this problem
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
