1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Fix a problem handling a malloc() failure in printf.c. Also some other things to improve test coverage. (CVS 4361)

FossilOrigin-Name: 595bfe72f053bc6ecb58bb9044a4cdc53d30b404
This commit is contained in:
danielk1977
2007-09-01 09:02:53 +00:00
parent 95c8a54c7d
commit ca0c89715e
10 changed files with 259 additions and 175 deletions

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the sqlite_*_printf() interface.
#
# $Id: printf.test,v 1.24 2007/05/10 17:23:12 drh Exp $
# $Id: printf.test,v 1.25 2007/09/01 09:02:54 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -293,4 +293,28 @@ do_test printf-15.3 {
sqlite3_snprintf_int 0 {} 0
} {abcdefghijklmnopqrstuvwxyz}
# Now test malloc() failure within a sqlite3_mprintf():
#
foreach var {a b c d} {
set $var [string repeat $var 400]
}
set str1 "[string repeat A 360]%d%d%s"
set str2 [string repeat B 5000]
set zSuccess "[string repeat A 360]11[string repeat B 5000]"
foreach ::iRepeat {0 1} {
set nTestNum 1
while {1} {
sqlite3_memdebug_fail $nTestNum -repeat $::iRepeat
set z [sqlite3_mprintf_str $str1 1 1 $str2]
set nFail [sqlite3_memdebug_fail -1 -benign nBenign]
do_test printf-malloc-$::iRepeat.$nTestNum {
expr {($nFail>0 && $z eq "") || ($nFail==$nBenign && $z eq $zSuccess)}
} {1}
if {$nFail == 0} break
incr nTestNum
}
}
finish_test