Rewrite the conversion functions between strings and SQL_NUMERIC_STRUCT.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 10 Jun 2014 10:35:05 +0000 (13:35 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 11 Jun 2014 21:11:43 +0000 (00:11 +0300)
commit0e8ad44a1556525b71293813af27ab0a9a605daf
tree83809d190e115fa1eef14cae095c1e401ad7c6fe
parente6d7dedf03deb73b6511bf60b1a5b453c246f137
Rewrite the conversion functions between strings and SQL_NUMERIC_STRUCT.

Aside from making the functions more readable and faster, this fixes
a number of bugs:

1. When converting a large number from decimal to binary, the least
significant byte might be wrong (reported by Walter Couto)

2. In binary->decimal conversion, a number with small precision but large
scale caused a "Floating point exception".

3. In binary->decimal conversion, building the final string was wrong, picking
up "digits" from outside the reserved stack space, if scale was larger than 40

4. The param_string buffer allocated for the result of binary->decimal
conversion was too small.

Also add a test cases for all of these bugs.
convert.c
test/Makefile.in
test/expected/numeric.out [new file with mode: 0644]
test/src/numeric-test.c [new file with mode: 0644]