SQLite4
Check-in [3cac6cdb86]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix sqlite4_num_to_text when formatting an integer with a negative exponent. It was leaving an uninitialized byte in the destination string.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | num_work
Files: files | file ages | folders
SHA1: 3cac6cdb864a4ecbdea82bc5441bc80914cb2275
User & Date: peterreid 2013-02-14 01:51:45
Context
2013-02-14
15:32
Fold in Peter Reid's fixes and enhancements to the sqlite4_num object. check-in: 8ede88c1df user: drh tags: trunk
01:51
Fix sqlite4_num_to_text when formatting an integer with a negative exponent. It was leaving an uninitialized byte in the destination string. Leaf check-in: 3cac6cdb86 user: peterreid tags: num_work
2013-02-11
14:03
Add test fixture functions for sqlite4_num_isinf and sqlite4_num_isnan, and some related test cases. check-in: 58a9cfcb39 user: peterreid tags: num_work
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/math.c.

   497    497       zNum += m;
   498    498       n -= m;
   499    499       removeTrailingZeros(zNum, &n);
   500    500       if( n>0 ){
   501    501         zOut[0] = '.';
   502    502         memcpy(zOut+1, zNum, n);
   503    503         nOut += n;
          504  +      zOut[n+1] = 0;
          505  +    }else{
          506  +      zOut[0] = 0;
   504    507       }
   505         -    zOut[n+1] = 0;
   506    508       return nOut;
   507    509     }
   508    510     if( x.e<0 && x.e >= -n-5 ){
   509    511       /* Values less than 1 and with no more than 5 subsequent zeros prior
   510    512       ** to the first significant digit.  Ex:  0.0000012345 */
   511    513       int j = -(n + x.e);
   512    514       memcpy(zOut, "0.", 2);

Changes to test/num.test.

    75     75   do_test num-5.1.1 {
    76     76     sqlite4_num_to_text [sqlite4_num_mul 9 8]
    77     77   } {72}
    78     78   
    79     79   do_test num-6.1.1 {
    80     80     sqlite4_num_to_text [sqlite4_num_div 6 5]
    81     81   } {1.2}
    82         -
    83         -
    84         -
    85         -
           82  +do_test num-6.1.2 {
           83  +  sqlite4_num_compare 2 [sqlite4_num_div 2 1]
           84  +} {equal}
           85  +do_test num-6.1.3 {
           86  +  sqlite4_num_to_text [sqlite4_num_div 2 1]
           87  +} {2}
           88  +do_test num-6.1.4 {
           89  +  sqlite4_num_to_text [sqlite4_num_div 22 10]
           90  +} {2.2}
    86     91   finish_test