mirror of
https://github.com/sqlite/sqlite.git
synced 2025-10-22 22:13:04 +03:00
Change sqlite3_snprintf() so that it does not write a zero-terminator if
the buffer size argument is less than 1. Ticket #2341. Added documentation about the sqlite3_snprintf() function. (CVS 3935) FossilOrigin-Name: f3ae4ac5fe0bfa2f91e76a6def86c444e51fe80b
This commit is contained in:
30
src/test1.c
30
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.248 2007/05/07 09:32:45 danielk1977 Exp $
|
||||
** $Id: test1.c,v 1.249 2007/05/07 11:24:30 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@@ -426,6 +426,33 @@ static int test_mprintf_n(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_snprintf_int SIZE FORMAT INT
|
||||
**
|
||||
** Test the of sqlite3_snprintf() routine. SIZE is the size of the
|
||||
** output buffer in bytes. The maximum size is 100. FORMAT is the
|
||||
** format string. INT is a single integer argument. The FORMAT
|
||||
** string must require no more than this one integer argument. If
|
||||
** You pass in a format string that requires more than one argument,
|
||||
** bad things will happen.
|
||||
*/
|
||||
static int test_snprintf_int(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
char zStr[100];
|
||||
int n = atoi(argv[1]);
|
||||
if( n>sizeof(zStr) ) n = sizeof(zStr);
|
||||
const char *zFormat = argv[2];
|
||||
int a1 = atoi(argv[3]);
|
||||
strcpy(zStr, "abcdefghijklmnopqrstuvwxyz");
|
||||
sqlite3_snprintf(n, zStr, zFormat, a1);
|
||||
Tcl_AppendResult(interp, zStr, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_get_table_printf DB FORMAT STRING
|
||||
**
|
||||
@@ -4609,6 +4636,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
{ "sqlite3_mprintf_hexdouble", (Tcl_CmdProc*)sqlite3_mprintf_hexdouble},
|
||||
{ "sqlite3_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z },
|
||||
{ "sqlite3_mprintf_n_test", (Tcl_CmdProc*)test_mprintf_n },
|
||||
{ "sqlite3_snprintf_int", (Tcl_CmdProc*)test_snprintf_int },
|
||||
{ "sqlite3_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid },
|
||||
{ "sqlite3_exec_printf", (Tcl_CmdProc*)test_exec_printf },
|
||||
{ "sqlite3_exec", (Tcl_CmdProc*)test_exec },
|
||||
|
||||
Reference in New Issue
Block a user