@@ -2336,7 +2336,7 @@ void format_decimal_numbers(_In_ SQLSMALLINT decimals_places, _In_ SQLSMALLINT f
2336
2336
//
2337
2337
2338
2338
// Check if it's a negative number and if necessary to add the leading zero
2339
- bool is_negative = (*field_value == ' -' );
2339
+ short is_negative = (*field_value == ' -' ) ? 1 : 0 ;
2340
2340
char *src = field_value + is_negative;
2341
2341
bool add_leading_zero = false ;
2342
2342
@@ -2354,12 +2354,12 @@ void format_decimal_numbers(_In_ SQLSMALLINT decimals_places, _In_ SQLSMALLINT f
2354
2354
scale = field_scale;
2355
2355
}
2356
2356
2357
- char buffer[50 ] = " " ; // A buffer with two blank spaces, as leeway
2358
- int offset = 1 + is_negative;
2357
+ char buffer[50 ] = " " ; // A buffer with TWO blank spaces, as leeway
2358
+ int offset = 1 + is_negative; // for cases like 9.* to 10.* and the minus sign if needed
2359
2359
int src_length = strnlen_s (src);
2360
2360
2361
2361
if (add_leading_zero) {
2362
- buffer[offset++] = ' 0' ;
2362
+ buffer[offset++] = ' 0' ; // leading zero added
2363
2363
}
2364
2364
// Copy the original numerical value to the buffer
2365
2365
memcpy_s (buffer + offset, src_length, src, src_length);
@@ -2375,10 +2375,11 @@ void format_decimal_numbers(_In_ SQLSMALLINT decimals_places, _In_ SQLSMALLINT f
2375
2375
}
2376
2376
}
2377
2377
2378
- // Remove the extra white space if not used
2379
- char *p = buffer;
2380
- offset = 0 ;
2381
- while (isspace (*p++)) {
2378
+ // Remove the extra white space if not used. For a negative number,
2379
+ // the first pos is always a space
2380
+ offset = is_negative;
2381
+ char *p = buffer + offset;
2382
+ while (*p++ == ' ' ) {
2382
2383
offset++;
2383
2384
}
2384
2385
if (is_negative) {
@@ -3017,23 +3018,23 @@ void adjustDecimalPrecision(_Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digi
3017
3018
return ;
3018
3019
}
3019
3020
3020
- // If std::stold() succeeds, 'idx ' is the position of the first character after the numerical value
3021
+ // If std::stold() succeeds, 'index ' is the position of the first character after the numerical value
3021
3022
long double d = 0 ;
3022
- size_t idx ;
3023
+ size_t index ;
3023
3024
try {
3024
- d = std::stold (std::string (value), &idx );
3025
+ d = std::stold (std::string (value), &index );
3025
3026
}
3026
3027
catch (const std::logic_error& ) {
3027
3028
return ; // invalid input caused the conversion to throw an exception
3028
3029
}
3029
- if (idx < value_len) {
3030
+ if (index < value_len) {
3030
3031
return ; // the input contains something else apart from the numerical value
3031
3032
}
3032
3033
3033
3034
// Navigate to the first digit or the decimal point
3034
- bool is_negative = (d < 0 );
3035
+ short is_negative = (d < 0 ) ? 1 : 0 ;
3035
3036
char *src = value + is_negative;
3036
- while (*src != DECIMAL_POINT && !isdigit (*src)) {
3037
+ while (*src != DECIMAL_POINT && !isdigit (static_cast < unsigned int >( *src) )) {
3037
3038
src++;
3038
3039
}
3039
3040
0 commit comments