/ Check-in [96a6d2d3]
Login

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

Overview
Comment:Test cases for printf of double overflows. (CVS 1260)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 96a6d2d3ff5bd0aaff188ee1c5e2f02cbea435b2
User & Date: drh 2004-02-21 19:41:04
Context
2004-02-22
00:08
Do not sort terminal symbols by name. The terminals remain in the same order that they are encountered in the grammar file. This results in parse tables that are 25% smaller. (CVS 1261) check-in: f36b122d user: drh tags: trunk
2004-02-21
19:41
Test cases for printf of double overflows. (CVS 1260) check-in: 96a6d2d3 user: drh tags: trunk
19:17
Fix a long-standing memory leak that the new last_insert_rowid() tests brought to light. (CVS 1259) check-in: 7d5ede5b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/printf.c.

   407    407           /* It makes more sense to use 0.5 */
   408    408           for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1);
   409    409   #endif
   410    410           if( infop->type==etFLOAT ) realvalue += rounder;
   411    411           /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
   412    412           exp = 0;
   413    413           if( realvalue>0.0 ){
   414         -          int k = 0;
   415         -          while( realvalue>=1e8 && k++<100 ){ realvalue *= 1e-8; exp+=8; }
   416         -          while( realvalue>=10.0 && k++<100 ){ realvalue *= 0.1; exp++; }
   417         -          while( realvalue<1e-8 && k++<100 ){ realvalue *= 1e8; exp-=8; }
   418         -          while( realvalue<1.0 && k++<100 ){ realvalue *= 10.0; exp--; }
   419         -          if( k>=100 ){
          414  +          while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
          415  +          while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
          416  +          while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
          417  +          while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
          418  +          if( exp>350 || exp<-350 ){
   420    419               bufpt = "NaN";
   421    420               length = 3;
   422    421               break;
   423    422             }
   424    423           }
   425    424           bufpt = buf;
   426    425           /*

Changes to src/test1.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the printf() interface to SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test1.c,v 1.34 2004/02/21 19:02:30 drh Exp $
           16  +** $Id: test1.c,v 1.35 2004/02/21 19:41:04 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include "os.h"
    21     21   #include <stdlib.h>
    22     22   #include <string.h>
    23     23   
................................................................................
   527    527     }
   528    528     if( Tcl_GetDouble(interp, argv[4], &r) ) return TCL_ERROR;
   529    529     z = sqlite_mprintf(argv[1], a[0], a[1], r);
   530    530     Tcl_AppendResult(interp, z, 0);
   531    531     sqlite_freemem(z);
   532    532     return TCL_OK;
   533    533   }
          534  +
          535  +/*
          536  +** Usage:  sqlite_mprintf_str FORMAT DOUBLE DOUBLE
          537  +**
          538  +** Call mprintf with a single double argument which is the product of the
          539  +** two arguments given above.  This is used to generate overflow and underflow
          540  +** doubles to test that they are converted properly.
          541  +*/
          542  +static int sqlite_mprintf_scaled(
          543  +  void *NotUsed,
          544  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
          545  +  int argc,              /* Number of arguments */
          546  +  char **argv            /* Text of each argument */
          547  +){
          548  +  int i;
          549  +  double r[2];
          550  +  char *z;
          551  +  if( argc!=4 ){
          552  +    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
          553  +       " FORMAT DOUBLE DOUBLE\"", 0);
          554  +    return TCL_ERROR;
          555  +  }
          556  +  for(i=2; i<4; i++){
          557  +    if( Tcl_GetDouble(interp, argv[i], &r[i-2]) ) return TCL_ERROR;
          558  +  }
          559  +  z = sqlite_mprintf(argv[1], r[0]*r[1]);
          560  +  Tcl_AppendResult(interp, z, 0);
          561  +  sqlite_freemem(z);
          562  +  return TCL_OK;
          563  +}
   534    564   
   535    565   /*
   536    566   ** Usage: sqlite_malloc_fail N
   537    567   **
   538    568   ** Rig sqliteMalloc() to fail on the N-th call.  Turn off this mechanism
   539    569   ** and reset the sqlite_malloc_failed variable is N==0.
   540    570   */
................................................................................
   948    978     static struct {
   949    979        char *zName;
   950    980        Tcl_CmdProc *xProc;
   951    981     } aCmd[] = {
   952    982        { "sqlite_mprintf_int",             (Tcl_CmdProc*)sqlite_mprintf_int    },
   953    983        { "sqlite_mprintf_str",             (Tcl_CmdProc*)sqlite_mprintf_str    },
   954    984        { "sqlite_mprintf_double",          (Tcl_CmdProc*)sqlite_mprintf_double },
          985  +     { "sqlite_mprintf_scaled",          (Tcl_CmdProc*)sqlite_mprintf_scaled },
   955    986        { "sqlite_mprintf_z_test",          (Tcl_CmdProc*)test_mprintf_z        },
   956    987        { "sqlite_open",                    (Tcl_CmdProc*)sqlite_test_open      },
   957    988        { "sqlite_last_insert_rowid",       (Tcl_CmdProc*)test_last_rowid       },
   958    989        { "sqlite_exec_printf",             (Tcl_CmdProc*)test_exec_printf      },
   959    990        { "sqlite_get_table_printf",        (Tcl_CmdProc*)test_get_table_printf },
   960    991        { "sqlite_close",                   (Tcl_CmdProc*)sqlite_test_close     },
   961    992        { "sqlite_create_function",         (Tcl_CmdProc*)test_create_function  },

Changes to test/printf.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the sqlite_*_printf() interface.
    13     13   #
    14         -# $Id: printf.test,v 1.7 2004/02/02 12:29:25 drh Exp $
           14  +# $Id: printf.test,v 1.8 2004/02/21 19:41:05 drh Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   set n 1
    20     20   foreach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} {
    21     21     do_test printf-1.$n.1 [subst {
................................................................................
   108    108     sqlite_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
   109    109   } {-9 -10 (HelloHello) %}
   110    110   
   111    111   do_test printf-6.1 {
   112    112     sqlite_mprintf_z_test , one two three four five six
   113    113   } {,one,two,three,four,five,six}
   114    114   
          115  +
          116  +do_test printf-7.1 {
          117  +  sqlite_mprintf_scaled {A double: %g} 1.0e307 1.0
          118  +} {A double: 1e+307}
          119  +do_test printf-7.2 {
          120  +  sqlite_mprintf_scaled {A double: %g} 1.0e307 10.0
          121  +} {A double: 1e+308}
          122  +do_test printf-7.3 {
          123  +  sqlite_mprintf_scaled {A double: %g} 1.0e307 100.0
          124  +} {A double: NaN}
          125  +
   115    126   finish_test