/ Check-in [db9acef1]
Login

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

Overview
Comment:Fix the round() SQL function so that it handles infinities correctly.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: db9acef14d49212108c8082cc15a9b9b4a56b8afe4fe1104ddf62783739c1fbe
User & Date: drh 2019-05-10 12:06:47
References
2019-05-10
12:14
Fix the previous check-in [db9acef14d492121] so that the amalgamation build works for systems for which lack HAVE_ISNAN. check-in: 3cc55e09 user: drh tags: trunk
Context
2019-05-10
12:14
Fix the previous check-in [db9acef14d492121] so that the amalgamation build works for systems for which lack HAVE_ISNAN. check-in: 3cc55e09 user: drh tags: trunk
12:06
Fix the round() SQL function so that it handles infinities correctly. check-in: db9acef1 user: drh tags: trunk
2019-05-09
18:37
Fix another small buffer overread in sqlite_dbdata triggered by a corrupt database page. check-in: 1dfc95b8 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/func.c.

    12     12   ** This file contains the C-language implementations for many of the SQL
    13     13   ** functions of SQLite.  (Some function, and in particular the date and
    14     14   ** time functions, are implemented separately.)
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include <stdlib.h>
    18     18   #include <assert.h>
           19  +#include <math.h>
    19     20   #include "vdbeInt.h"
    20     21   
    21     22   /*
    22     23   ** Return the collating function associated with a function.
    23     24   */
    24     25   static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
    25     26     VdbeOp *pOp;
................................................................................
   392    393       r = -(double)((sqlite_int64)((-r)+0.5));
   393    394     }else{
   394    395       zBuf = sqlite3_mprintf("%.*f",n,r);
   395    396       if( zBuf==0 ){
   396    397         sqlite3_result_error_nomem(context);
   397    398         return;
   398    399       }
   399         -    sqlite3AtoF(zBuf, &r, sqlite3Strlen30(zBuf), SQLITE_UTF8);
          400  +    if( !sqlite3AtoF(zBuf, &r, sqlite3Strlen30(zBuf), SQLITE_UTF8) ){
          401  +      assert( sqlite3_strglob("*Inf", zBuf)==0 );
          402  +      r = zBuf[0]=='-' ? -HUGE_VAL : +HUGE_VAL;
          403  +    } 
   400    404       sqlite3_free(zBuf);
   401    405     }
   402    406     sqlite3_result_double(context, r);
   403    407   }
   404    408   #endif
   405    409   
   406    410   /*

Changes to test/func.test.

   311    311     } {99999999999995.0}
   312    312     do_test func-4.37 {
   313    313       execsql {SELECT round(9999999999999.55,1);}
   314    314     } {9999999999999.6}
   315    315     do_test func-4.38 {
   316    316       execsql {SELECT round(9999999999999.556,2);}
   317    317     } {9999999999999.56}
          318  +  do_execsql_test func-4.39 {
          319  +    SELECT round(1e500), round(-1e500);
          320  +  } {Inf -Inf}
   318    321   }
   319    322   
   320    323   # Test the upper() and lower() functions
   321    324   #
   322    325   do_test func-5.1 {
   323    326     execsql {SELECT upper(t1) FROM tbl1}
   324    327   } {THIS PROGRAM IS FREE SOFTWARE}