summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-06-15 22:58:46 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-06-15 22:58:46 -0700
commit207bc788e93a40460c36bfbb9f2af9927b87de9b (patch)
tree7f21822887b9e0625ac5bf039971f84dc7d5c5d8 /src
parentcd2804d3ee14487fc1af0ecaa05ffbe7baba5635 (diff)
Use buffer with a static size in convert_number_to_mantissa_exponent
We use references to arrays elsewhere in the codebase and there's just one caller for this function so it's easier to fix the size. This will simplify snprintf refactoring.
Diffstat (limited to 'src')
-rw-r--r--src/pugixml.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index ac036e3..518ceec 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -7998,11 +7998,11 @@ PUGI__NS_BEGIN
// gets mantissa digits in the form of 0.xxxxx with 0. implied and the exponent
#if defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 && !defined(_WIN32_WCE)
- PUGI__FN void convert_number_to_mantissa_exponent(double value, char* buffer, size_t buffer_size, char** out_mantissa, int* out_exponent)
+ PUGI__FN void convert_number_to_mantissa_exponent(double value, char (&buffer)[32], char** out_mantissa, int* out_exponent)
{
// get base values
int sign, exponent;
- _ecvt_s(buffer, buffer_size, value, DBL_DIG + 1, &exponent, &sign);
+ _ecvt_s(buffer, sizeof(buffer), value, DBL_DIG + 1, &exponent, &sign);
// truncate redundant zeros
truncate_zeros(buffer, buffer + strlen(buffer));
@@ -8012,20 +8012,18 @@ PUGI__NS_BEGIN
*out_exponent = exponent;
}
#else
- PUGI__FN void convert_number_to_mantissa_exponent(double value, char* buffer, size_t buffer_size, char** out_mantissa, int* out_exponent)
+ PUGI__FN void convert_number_to_mantissa_exponent(double value, char (&buffer)[32], char** out_mantissa, int* out_exponent)
{
// get a scientific notation value with IEEE DBL_DIG decimals
#if defined(PUGI__HAVE_SNPRINTF)
- snprintf(buffer, buffer_size, "%.*e", DBL_DIG, value);
+ snprintf(buffer, 32, "%.*e", DBL_DIG, value);
#elif defined(PUGI__MSVC_CRT_VERSION)
- _snprintf(buffer, buffer_size, "%.*e", DBL_DIG, value);
- buffer[buffer_size - 1] = '\0';
+ _snprintf(buffer, 32, "%.*e", DBL_DIG, value);
+ buffer[31] = '\0';
#else
sprintf(buffer, "%.*e", DBL_DIG, value);
- assert(strlen(buffer) < buffer_size);
#endif
-
// get the exponent (possibly negative)
char* exponent_string = strchr(buffer, 'e');
assert(exponent_string);
@@ -8061,7 +8059,7 @@ PUGI__NS_BEGIN
char* mantissa;
int exponent;
- convert_number_to_mantissa_exponent(value, mantissa_buffer, sizeof(mantissa_buffer), &mantissa, &exponent);
+ convert_number_to_mantissa_exponent(value, mantissa_buffer, &mantissa, &exponent);
// allocate a buffer of suitable length for the number
size_t result_size = strlen(mantissa_buffer) + (exponent > 0 ? exponent : -exponent) + 4;