SQLite4
Check-in [24ee36b76f]
Not logged in

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

Overview
Comment:Fix defect in which sqlite4_num_from_text returns NaN if it uses exactly as many bytes as the caller allows.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | num_work
Files: files | file ages | folders
SHA1: 24ee36b76f0772b140871a121213607267fe807b
User & Date: peterreid 2013-02-10 19:21:53
Context
2013-02-10
22:03
Add sqlite4_num_add/sub/mul/div to testfixture and some tests that use them. check-in: 91bfc9e7d7 user: peterreid tags: num_work
19:21
Fix defect in which sqlite4_num_from_text returns NaN if it uses exactly as many bytes as the caller allows. check-in: 24ee36b76f user: peterreid tags: num_work
04:26
Add a failing test and supporting functions. When the buffer is ended by a passed-in byte count instead of a trailing 0, sqlite4_num_from_text returns NaN check-in: 2cff3b428a user: peterreid tags: num_work
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/math.c.

   359    359           if( seenRadix ) r.e--;
   360    360         }else{
   361    361           if( c!='0' ) r.approx = 1;
   362    362           if( !seenRadix ) r.e++;
   363    363         }
   364    364       }else if( c=='.' ){
   365    365         seenRadix = 1;
   366         -    }else{
          366  +    }else if( c=='e' || c=='E' ){
          367  +      int exp = 0;
          368  +      int expsign = 0;
          369  +      int nEDigit = 0;
          370  +      if( zIn[i]=='-' ){
          371  +        expsign = 1;
          372  +        i += incr;
          373  +      }else if( zIn[i]=='+' ){
          374  +        i += incr;
          375  +      }
          376  +      if( i>=nIn ) goto not_a_valid_number;
          377  +      while( i<nIn && (c = zIn[i])!=0 ){
          378  +        i += incr;
          379  +        if( c<'0' || c>'9' ) goto not_a_valid_number;
          380  +        if( c=='0' && nEDigit==0 ) continue;
          381  +        nEDigit++;
          382  +        if( nEDigit>3 ) goto not_a_valid_number;
          383  +        exp = exp*10 + c - '0';
          384  +      }
          385  +      if( expsign ) exp = -exp;
          386  +      r.e += exp;
   367    387         break;
          388  +    }else{
          389  +      goto not_a_valid_number;
   368    390       }
   369    391     }
   370         -  if( c=='e' || c=='E' ){
   371         -    int exp = 0;
   372         -    int expsign = 0;
   373         -    int nEDigit = 0;
   374         -    if( zIn[i]=='-' ){
   375         -      expsign = 1;
   376         -      i += incr;
   377         -    }else if( zIn[i]=='+' ){
   378         -      i += incr;
   379         -    }
   380         -    if( i>=nIn ) goto not_a_valid_number;
   381         -    while( i<nIn && (c = zIn[i])!=0  ){
   382         -      i += incr;
   383         -      if( c<'0' || c>'9' ) break;
   384         -      if( c=='0' && nEDigit==0 ) continue;
   385         -      nEDigit++;
   386         -      if( nEDigit>3 ) goto not_a_valid_number;
   387         -      exp = exp*10 + c - '0';
   388         -    }
   389         -    if( expsign ) exp = -exp;
   390         -    r.e += exp;
   391         -  }
   392         -  if( c!=0 ) goto not_a_valid_number;
   393    392     return r;
   394    393     
   395    394   not_a_valid_number:
   396    395     r.e = SQLITE4_MX_EXP+1;
   397    396     r.m = 0;
   398    397     return r;  
   399    398   }