Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix signed integer problems in vxprintf. Ticket #778. Also remove some dead code from util.c. (CVS 1685) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
200cd3baf60e6cfad9fa397183436782 |
User & Date: | drh 2004-06-25 01:10:48.000 |
Context
2004-06-25
| ||
02:38 | Modifications to the journal format to make it more robust. (CVS 1686) (check-in: 504246a18d user: danielk1977 tags: trunk) | |
01:10 | Fix signed integer problems in vxprintf. Ticket #778. Also remove some dead code from util.c. (CVS 1685) (check-in: 200cd3baf6 user: drh tags: trunk) | |
2004-06-24
| ||
15:09 | add all sqlite3_ functions in capi reference to dll exports (CVS 1684) (check-in: b6ca51e47a user: dougcurrie tags: trunk) | |
Changes
Changes to src/printf.c.
︙ | ︙ | |||
341 342 343 344 345 346 347 | ** precision The specified precision. The default ** is -1. ** xtype The class of the conversion. ** infop Pointer to the appropriate info struct. */ switch( xtype ){ case etRADIX: | < < < < < < < < < < < < > | > > | | | > > | > | < | < | < | > | < > | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | ** precision The specified precision. The default ** is -1. ** xtype The class of the conversion. ** infop Pointer to the appropriate info struct. */ switch( xtype ){ case etRADIX: if( infop->flags & FLAG_SIGNED ){ i64 v; if( flag_longlong ) v = va_arg(ap,i64); else if( flag_long ) v = va_arg(ap,long int); else v = va_arg(ap,int); if( v<0 ){ longvalue = -v; prefix = '-'; }else{ longvalue = v; if( flag_plussign ) prefix = '+'; else if( flag_blanksign ) prefix = ' '; else prefix = 0; } }else{ if( flag_longlong ) longvalue = va_arg(ap,u64); else if( flag_long ) longvalue = va_arg(ap,unsigned long int); else longvalue = va_arg(ap,unsigned int); prefix = 0; } if( longvalue==0 ) flag_alternateform = 0; if( flag_zeropad && precision<width-(prefix!=0) ){ precision = width-(prefix!=0); } bufpt = &buf[etBUFSIZE-1]; { register char *cset; /* Use registers for speed */ register int base; |
︙ | ︙ |
Changes to src/test1.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** ** $Id: test1.c,v 1.87 2004/06/25 01:10:48 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" #include "os.h" #include <stdlib.h> #include <string.h> |
︙ | ︙ | |||
534 535 536 537 538 539 540 541 542 543 544 545 546 547 | if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; } z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK; } /* ** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING ** ** Call mprintf with two integer arguments and one string argument */ static int sqlite3_mprintf_str( | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; } z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK; } /* ** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER ** ** Call mprintf with three 64-bit integer arguments */ static int sqlite3_mprintf_int64( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */ ){ int i; sqlite_int64 a[3]; char *z; if( argc!=5 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FORMAT INT INT INT\"", 0); return TCL_ERROR; } for(i=2; i<5; i++){ if( !sqlite3GetInt64(argv[i], &a[i-2]) ){ Tcl_AppendResult(interp, "argument is not a valid 64-bit integer", 0); return TCL_ERROR; } } z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK; } /* ** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING ** ** Call mprintf with two integer arguments and one string argument */ static int sqlite3_mprintf_str( |
︙ | ︙ | |||
980 981 982 983 984 985 986 | bad_args: Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0); return TCL_ERROR; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | | | | 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 | bad_args: Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0); return TCL_ERROR; } static int sqlite3_crashseed( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ #ifdef OS_TEST int seed; if( objc!=2 ) goto bad_args; if( Tcl_GetIntFromObj(interp, objv[1], &seed) ) return TCL_ERROR; sqlite3SetCrashseed(seed); #endif return TCL_OK; #ifdef OS_TEST bad_args: Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), "<seed>", 0); return TCL_ERROR; #endif } /* ** Usage: breakpoint |
︙ | ︙ | |||
2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 | extern int sqlite3_open_file_count; extern int sqlite3_current_time; static struct { char *zName; Tcl_CmdProc *xProc; } aCmd[] = { { "sqlite3_mprintf_int", (Tcl_CmdProc*)sqlite3_mprintf_int }, { "sqlite3_mprintf_str", (Tcl_CmdProc*)sqlite3_mprintf_str }, { "sqlite3_mprintf_double", (Tcl_CmdProc*)sqlite3_mprintf_double }, { "sqlite3_mprintf_scaled", (Tcl_CmdProc*)sqlite3_mprintf_scaled }, { "sqlite3_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z }, { "sqlite3_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid }, { "sqlite3_exec_printf", (Tcl_CmdProc*)test_exec_printf }, { "sqlite3_get_table_printf", (Tcl_CmdProc*)test_get_table_printf }, | > | 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 | extern int sqlite3_open_file_count; extern int sqlite3_current_time; static struct { char *zName; Tcl_CmdProc *xProc; } aCmd[] = { { "sqlite3_mprintf_int", (Tcl_CmdProc*)sqlite3_mprintf_int }, { "sqlite3_mprintf_int64", (Tcl_CmdProc*)sqlite3_mprintf_int64 }, { "sqlite3_mprintf_str", (Tcl_CmdProc*)sqlite3_mprintf_str }, { "sqlite3_mprintf_double", (Tcl_CmdProc*)sqlite3_mprintf_double }, { "sqlite3_mprintf_scaled", (Tcl_CmdProc*)sqlite3_mprintf_scaled }, { "sqlite3_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z }, { "sqlite3_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid }, { "sqlite3_exec_printf", (Tcl_CmdProc*)test_exec_printf }, { "sqlite3_get_table_printf", (Tcl_CmdProc*)test_get_table_printf }, |
︙ | ︙ | |||
2193 2194 2195 2196 2197 2198 2199 | /* Functions from os.h */ { "sqlite3OsOpenReadWrite",test_sqlite3OsOpenReadWrite, 0 }, { "sqlite3OsClose", test_sqlite3OsClose, 0 }, { "sqlite3OsLock", test_sqlite3OsLock, 0 }, { "sqlite3OsUnlock", test_sqlite3OsUnlock, 0 }, { "add_test_collate", test_collate, 0 }, | < | | 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 | /* Functions from os.h */ { "sqlite3OsOpenReadWrite",test_sqlite3OsOpenReadWrite, 0 }, { "sqlite3OsClose", test_sqlite3OsClose, 0 }, { "sqlite3OsLock", test_sqlite3OsLock, 0 }, { "sqlite3OsUnlock", test_sqlite3OsUnlock, 0 }, { "add_test_collate", test_collate, 0 }, { "sqlite3_crashseed", sqlite3_crashseed, 0 }, }; int i; extern int sqlite3_os_trace; for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); |
︙ | ︙ |
Changes to src/util.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** ** $Id: util.c,v 1.107 2004/06/25 01:10:48 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> #include <ctype.h> #if SQLITE_DEBUG>2 && defined(__GLIBC__) #include <execinfo.h> |
︙ | ︙ | |||
770 771 772 773 774 775 776 | if( sqlite3FitsIn64Bits(zNum) ){ sqlite3atoi64(zNum, pValue); return 1; } return 0; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | if( sqlite3FitsIn64Bits(zNum) ){ sqlite3atoi64(zNum, pValue); return 1; } return 0; } #if 1 /* We are now always UTF-8 */ /* ** X is a pointer to the first byte of a UTF-8 character. Increment ** X so that it points to the next character. This only works right ** if X points to a well-formed UTF-8 string. */ #define sqliteNextChar(X) while( (0xc0&*++(X))==0x80 ){} |
︙ | ︙ |
Changes to test/printf.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the sqlite_*_printf() interface. # | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the sqlite_*_printf() interface. # # $Id: printf.test,v 1.10 2004/06/25 01:10:48 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl set n 1 foreach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} { do_test printf-1.$n.1 [subst { sqlite3_mprintf_int {Three integers: %d %x %o} $v $v $v }] [format {Three integers: %d %x %o} $v $v $v] do_test printf-1.$n.2 [subst { sqlite3_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v $v] do_test printf-1.$n.3 [subst { sqlite3_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v] do_test printf-1.$n.4 [subst { sqlite3_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v] do_test printf-1.$n.5 [subst { sqlite3_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v $v] do_test printf-1.$n.6 [subst { sqlite3_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v] incr n } if {$::tcl_platform(platform)!="windows"} { set m 1 |
︙ | ︙ | |||
119 120 121 122 123 124 125 126 | do_test printf-7.2 { sqlite3_mprintf_scaled {A double: %g} 1.0e307 10.0 } {A double: 1e+308} do_test printf-7.3 { sqlite3_mprintf_scaled {A double: %g} 1.0e307 100.0 } {A double: NaN} finish_test | > > > > > > > > > > > > > > > > > > > | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | do_test printf-7.2 { sqlite3_mprintf_scaled {A double: %g} 1.0e307 10.0 } {A double: 1e+308} do_test printf-7.3 { sqlite3_mprintf_scaled {A double: %g} 1.0e307 100.0 } {A double: NaN} do_test printf-8.1 { sqlite3_mprintf_int {%u %u %u} 0x7fffffff 0x80000000 0xffffffff } {2147483647 2147483648 4294967295} do_test printf-8.2 { sqlite3_mprintf_int {%lu %lu %lu} 0x7fffffff 0x80000000 0xffffffff } {2147483647 2147483648 4294967295} do_test printf-8.3 { sqlite3_mprintf_int64 {%llu %llu %llu} 2147483647 2147483648 4294967296 } {2147483647 2147483648 4294967296} do_test printf-8.4 { sqlite3_mprintf_int64 {%lld %lld %lld} 2147483647 2147483648 4294967296 } {2147483647 2147483648 4294967296} do_test printf-8.5 { sqlite3_mprintf_int64 {%llx %llx %llx} 2147483647 2147483648 4294967296 } {7fffffff 80000000 100000000} do_test printf-8.6 { sqlite3_mprintf_int64 {%llx %llo %lld} -1 -1 -1 } {ffffffffffffffff 1777777777777777777777 -1} finish_test |