diff options
author | drh <drh@noemail.net> | 2004-07-17 21:56:09 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2004-07-17 21:56:09 +0000 |
commit | e29b1a05a7e86fdd5bb58cd2f4f8bbc700bb01f3 (patch) | |
tree | 39a8842f15b5a12cc67846cfdc964486bd91da45 /src | |
parent | dd809b087f91fd906ba701da8487254eb16a8db0 (diff) | |
download | sqlite-e29b1a05a7e86fdd5bb58cd2f4f8bbc700bb01f3.tar.gz sqlite-e29b1a05a7e86fdd5bb58cd2f4f8bbc700bb01f3.zip |
mprintf() correctly handles "%s","". Fix for ticket #812. (CVS 1800)
FossilOrigin-Name: 4f56db1149f65dc2edf6626fa20ae255a5f5280c
Diffstat (limited to 'src')
-rw-r--r-- | src/printf.c | 9 | ||||
-rw-r--r-- | src/test1.c | 28 |
2 files changed, 33 insertions, 4 deletions
diff --git a/src/printf.c b/src/printf.c index a190a1017..2ed674a88 100644 --- a/src/printf.c +++ b/src/printf.c @@ -228,6 +228,7 @@ static int vxprintf( int nsd; /* Number of significant digits returned */ #endif + func(arg,"",0); count = length = 0; bufpt = 0; for(; (c=(*fmt))!=0; ++fmt){ @@ -684,9 +685,11 @@ static void mout(void *arg, const char *zNewText, int nNewChar){ } } } - if( pM->zText && nNewChar>0 ){ - memcpy(&pM->zText[pM->nChar], zNewText, nNewChar); - pM->nChar += nNewChar; + if( pM->zText ){ + if( nNewChar>0 ){ + memcpy(&pM->zText[pM->nChar], zNewText, nNewChar); + pM->nChar += nNewChar; + } pM->zText[pM->nChar] = 0; } } diff --git a/src/test1.c b/src/test1.c index 38271b6cf..852a1649f 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.93 2004/07/15 14:15:02 drh Exp $ +** $Id: test1.c,v 1.94 2004/07/17 21:56:10 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -670,6 +670,31 @@ static int sqlite3_mprintf_scaled( } /* +** Usage: sqlite3_mprintf_stronly FORMAT STRING +** +** Call mprintf with a single double argument which is the product of the +** two arguments given above. This is used to generate overflow and underflow +** doubles to test that they are converted properly. +*/ +static int sqlite3_mprintf_stronly( + void *NotUsed, + Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ + int argc, /* Number of arguments */ + char **argv /* Text of each argument */ +){ + char *z; + if( argc!=3 ){ + Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], + " FORMAT STRING\"", 0); + return TCL_ERROR; + } + z = sqlite3_mprintf(argv[1], argv[2]); + Tcl_AppendResult(interp, z, 0); + sqlite3_free(z); + return TCL_OK; +} + +/* ** Usage: sqlite_malloc_fail N ** ** Rig sqliteMalloc() to fail on the N-th call. Turn off this mechanism @@ -2287,6 +2312,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "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_stronly", (Tcl_CmdProc*)sqlite3_mprintf_stronly}, { "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 }, |