nagyistoce / stringencoders

Automatically exported from code.google.com/p/stringencoders
Other
0 stars 0 forks source link

modp_litoa10 truncates value if sizeof(unsigned long) is not 8 #26

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The modp_litoa10 does the majority of its work on uvalue, which is an unsigned 
long.  If an unsigned long is not 64-bits wide, the input number will be 
truncated. 

    unsigned long uvalue = (value < 0) ? -value : value;

Fix:  Change the declaration of uvalue to uint64_t.

    uint64_t uvalue = (value < 0) ? -value : value;

Original issue reported on code.google.com by ind...@gmail.com on 9 Feb 2012 at 8:25

GoogleCodeExporter commented 9 years ago
Thanks for this report.  This is now fixed!

Committed revision 260.
$ svn diff -rPREV !$
svn diff -rPREV src/modp_numtoa.c
Index: src/modp_numtoa.c
===================================================================
--- src/modp_numtoa.c   (revision 259)
+++ src/modp_numtoa.c   (working copy)
@@ -58,7 +58,7 @@
 void modp_litoa10(int64_t value, char* str)
 {
     char* wstr=str;
-    unsigned long uvalue = (value < 0) ? -value : value;
+    uint64_t uvalue = (value < 0) ? -value : value;

     // Conversion. Number is reversed.
     do *wstr++ = (char)(48 + (uvalue % 10)); while(uvalue /= 10);

Original comment by nickg@client9.com on 25 Feb 2012 at 4:02