Index: src/vdbemem.c ================================================================== --- src/vdbemem.c +++ src/vdbemem.c @@ -160,11 +160,14 @@ return SQLITE_OK; /* Nothing to do */ } if( pMem->flags & (MEM_Static|MEM_Ephem) ){ return sqlite3VdbeMemMakeWriteable(pMem); }else{ - char *z = sqliteMalloc(pMem->n+2); + char *z; + sqlite3VdbeMemExpandBlob(pMem); + z = sqliteMalloc(pMem->n+2); + if( !z ) return SQLITE_NOMEM; memcpy(z, pMem->z, pMem->n); z[pMem->n] = 0; z[pMem->n+1] = 0; if( pMem->xDel ){ Index: test/zeroblob.test ================================================================== --- test/zeroblob.test +++ test/zeroblob.test @@ -11,11 +11,11 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing of the zero-filled blob functionality # including the sqlite3_bind_zeroblob(), sqlite3_result_zeroblob(), # and the built-in zeroblob() SQL function. # -# $Id: zeroblob.test,v 1.4 2007/05/23 06:31:39 drh Exp $ +# $Id: zeroblob.test,v 1.5 2007/05/30 06:19:33 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl ifcapable !incrblob { @@ -125,8 +125,31 @@ do_test zeroblob-4.1 { execsql { SELECT hex(zeroblob(2) || x'61') } } {000061} + +# Check various CAST(...) operations on zeroblob. +# +do_test zeroblob-5.1 { + execsql { + SELECT CAST (zeroblob(100) AS REAL); + } +} {0.0} +do_test zeroblob-5.2 { + execsql { + SELECT CAST (zeroblob(100) AS INTEGER); + } +} {0} +do_test zeroblob-5.3 { + execsql { + SELECT CAST (zeroblob(100) AS TEXT); + } +} {{}} +do_test zeroblob-5.4 { + execsql { + SELECT CAST(zeroblob(100) AS BLOB); + } +} [execsql {SELECT zeroblob(100)}] finish_test