@@ -27,13 +27,13 @@ php_cassandra_parse_integer(char* in, int in_len, mpz_t* number)
27
27
if (in [point ] == '0' ) {
28
28
switch (in [point + 1 ]) {
29
29
case 'b' :
30
+ point += 2 ;
30
31
base = 2 ;
31
32
break ;
32
33
case 'x' :
34
+ point += 2 ;
33
35
base = 16 ;
34
36
break ;
35
- case '.' :
36
- break ;
37
37
default :
38
38
base = 8 ;
39
39
break ;
@@ -55,6 +55,11 @@ php_cassandra_parse_integer(char* in, int in_len, mpz_t* number)
55
55
return 0 ;
56
56
}
57
57
58
+ if (end != & in [in_len ]) {
59
+ zend_throw_exception_ex (cassandra_ce_InvalidArgumentException , 0 TSRMLS_CC , "Non digit characters were found in value: '%s'" , in );
60
+ return 0 ;
61
+ }
62
+
58
63
if (end == & in [point ]) {
59
64
zend_throw_exception_ex (cassandra_ce_InvalidArgumentException , 0 TSRMLS_CC , "No digits were found in value: \"%s\"" , in );
60
65
return 0 ;
@@ -93,7 +98,7 @@ php_cassandra_parse_decimal(char* in, int in_len, mpz_t* number, int* scale)
93
98
int dot = -1 ;
94
99
// out will be storing the string representation of the integer part
95
100
// of the decimal value
96
- char * out = (char * ) emalloc ((in_len + 1 ) * sizeof (char ));
101
+ char * out = (char * ) ecalloc ((in_len + 1 ), sizeof (char ));
97
102
// holds length of the formatted integer number
98
103
int out_len = 0 ;
99
104
@@ -158,9 +163,9 @@ php_cassandra_parse_decimal(char* in, int in_len, mpz_t* number, int* scale)
158
163
else if (c == 'e' || c == 'E' )
159
164
break ;
160
165
// Throw an exception if the character was not a decimal or an
161
- // exponent and is not a digit.
162
- else if (!isdigit (c )) {
163
- zend_throw_exception_ex (cassandra_ce_InvalidArgumentException , 0 TSRMLS_CC , "Unrecognized character at %d: %c " , point , c );
166
+ // exponent and is not a hexadecimal digit.
167
+ else if (!isxdigit (c )) {
168
+ zend_throw_exception_ex (cassandra_ce_InvalidArgumentException , 0 TSRMLS_CC , "Unrecognized character '%c' at %d" , c , point );
164
169
return 0 ;
165
170
}
166
171
@@ -177,13 +182,13 @@ php_cassandra_parse_decimal(char* in, int in_len, mpz_t* number, int* scale)
177
182
memcpy (& out [negative ], & in [start ], dot - start );
178
183
memcpy (& out [negative + dot - start ], & in [dot + 1 ], point - dot );
179
184
180
- out_len = point - start ;
185
+ out_len = point - start + negative ;
181
186
* scale = point - 1 - dot ;
182
187
} else {
183
188
// If there was no decimal then the unscaled value is just the number
184
189
// formed from all the digits and the scale is zero.
185
190
memcpy (& out [negative ], & in [start ], point - start );
186
- out_len = point - start ;
191
+ out_len = point - start + negative ;
187
192
* scale = 0 ;
188
193
}
189
194
@@ -195,8 +200,8 @@ php_cassandra_parse_decimal(char* in, int in_len, mpz_t* number, int* scale)
195
200
int ok = php_cassandra_parse_integer (out , out_len , number );
196
201
197
202
if (!ok ) {
198
- efree (out );
199
203
zend_throw_exception_ex (cassandra_ce_InvalidArgumentException , 0 TSRMLS_CC , "Unable to extract integer part of decimal value: \"%s\", %s" , in , out );
204
+ efree (out );
200
205
return 0 ;
201
206
}
202
207
efree (out );
0 commit comments