forked from scylladb/scylla-seastar
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: to_sstring_strintf(): always use %g(or %lg) format for floating…
… point values Current implementation of to_sstring_strintf() and to_sstring() functions may cause memory overrun and trashing for floating point values: to_sstring_sprintf() uses an internal buffer of (3 * sizeof(value type) + 3) bytes for an output string but this may not be enough for some floating point values, e.g. for float values like 1e-23 or 1e+23, since to_string(float) uses %f format. %g and %lg printf formats on the other hand allow us to use integer values induced upper estimate for an output string length (3 * sizeof(value type) + 2) since it covers the longest floating point values output for this format too: - 13 for a float (4 bytes value). - 14 for a double (8 bytes value). - 15 for a long double (10 bytes value). This way we may significantly simplify the to_sstring_strintf() implementation while ensuring that there won't be any memory trashing. Signed-off-by: Vlad Zolotarov <[email protected]>
- Loading branch information
Showing
3 changed files
with
7 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters