@@ -27,13 +27,13 @@ php_cassandra_parse_integer(char* in, int in_len, mpz_t* number)
2727 if (in [point ] == '0' ) {
2828 switch (in [point + 1 ]) {
2929 case 'b' :
30+ point += 2 ;
3031 base = 2 ;
3132 break ;
3233 case 'x' :
34+ point += 2 ;
3335 base = 16 ;
3436 break ;
35- case '.' :
36- break ;
3737 default :
3838 base = 8 ;
3939 break ;
@@ -55,6 +55,11 @@ php_cassandra_parse_integer(char* in, int in_len, mpz_t* number)
5555 return 0 ;
5656 }
5757
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+
5863 if (end == & in [point ]) {
5964 zend_throw_exception_ex (cassandra_ce_InvalidArgumentException , 0 TSRMLS_CC , "No digits were found in value: \"%s\"" , in );
6065 return 0 ;
@@ -93,7 +98,7 @@ php_cassandra_parse_decimal(char* in, int in_len, mpz_t* number, int* scale)
9398 int dot = -1 ;
9499 // out will be storing the string representation of the integer part
95100 // of the decimal value
96- char * out = (char * ) emalloc ((in_len + 1 ) * sizeof (char ));
101+ char * out = (char * ) ecalloc ((in_len + 1 ), sizeof (char ));
97102 // holds length of the formatted integer number
98103 int out_len = 0 ;
99104
@@ -158,9 +163,9 @@ php_cassandra_parse_decimal(char* in, int in_len, mpz_t* number, int* scale)
158163 else if (c == 'e' || c == 'E' )
159164 break ;
160165 // 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 );
164169 return 0 ;
165170 }
166171
@@ -177,13 +182,13 @@ php_cassandra_parse_decimal(char* in, int in_len, mpz_t* number, int* scale)
177182 memcpy (& out [negative ], & in [start ], dot - start );
178183 memcpy (& out [negative + dot - start ], & in [dot + 1 ], point - dot );
179184
180- out_len = point - start ;
185+ out_len = point - start + negative ;
181186 * scale = point - 1 - dot ;
182187 } else {
183188 // If there was no decimal then the unscaled value is just the number
184189 // formed from all the digits and the scale is zero.
185190 memcpy (& out [negative ], & in [start ], point - start );
186- out_len = point - start ;
191+ out_len = point - start + negative ;
187192 * scale = 0 ;
188193 }
189194
@@ -195,8 +200,8 @@ php_cassandra_parse_decimal(char* in, int in_len, mpz_t* number, int* scale)
195200 int ok = php_cassandra_parse_integer (out , out_len , number );
196201
197202 if (!ok ) {
198- efree (out );
199203 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 );
200205 return 0 ;
201206 }
202207 efree (out );
0 commit comments