Add the sqlite3_result_zeroblob64() API. Use it in the SQL zeroblob() function.

FossilOrigin-Name: c6445b9fb4d7d1a8479436d7d183bad754a01615
This commit is contained in:
dan
2015-07-24 16:24:37 +00:00
parent 53e66c3cda
commit a4d5ae8fa2
7 changed files with 55 additions and 20 deletions
+11 -11
View File
@@ -1,5 +1,5 @@
C More\srobust\shandling\sof\szeroblob()\swith\soversized\sarguments.\s\sFix\sfuzzcheck\nso\sthat\sit\scan\sbe\srun\swith\slimited\sheap\smemory.
D 2015-07-24T15:49:23.313
C Add\sthe\ssqlite3_result_zeroblob64()\sAPI.\sUse\sit\sin\sthe\sSQL\szeroblob()\sfunction.
D 2015-07-24T16:24:37.673
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 6a2355cacb04337e6f29a95200512b1cdd8c1857
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -282,7 +282,7 @@ F src/delete.c 8857a6f27560718f65d43bdbec86c967ae1f8dfa
F src/expr.c c5c58e4d01c7ceb2266791d8d877f1b23a88e316
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c c9b63a217d86582c22121699a47f22f524608869
F src/func.c d08d2106ba10dddbee45e001b8516f4d1df2b20e
F src/func.c 7810a7e88340f1fc1173cd0ac1461dc809c32039
F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9
F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5
F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094
@@ -329,9 +329,9 @@ F src/resolve.c 2d47554370de8de6dd5be060cef9559eec315005
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
F src/select.c 57ef3d98c4400b93eea318813be41b2af2da2217
F src/shell.c 8af3cced094aebb5f57a8ad739b9dafc7867eed7
F src/sqlite.h.in ae2a0ceb9d65880437d56dfa9bd9ed1af7d36fce
F src/sqlite.h.in f589633da2c6b55bb9eef525eb8ab918693a95a2
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
F src/sqlite3ext.h be1a718b7d2ce40ceba725ae92c8eb5f18003066
F src/sqlite3ext.h 3d12a31e2346ce8c00c189bc5816d056d4f36c5f
F src/sqliteInt.h c67d0a1368484dd156e7d13caa62862adc2ebefa
F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46
F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179
@@ -393,7 +393,7 @@ F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701
F src/vdbe.c 86be40a4568f5385048ea6623adfd11ddb7bf710
F src/vdbe.h 7a75045d879118b9d3af7e8b3c108f2f27c51473
F src/vdbeInt.h 8b54e01ad0463590e7cffabce0bc36da9ee4f816
F src/vdbeapi.c 082746d4c4788d889a2a62b858d753453e9c9c6d
F src/vdbeapi.c a0ffa364a7a65a401a1784d4cae60b4fbb5851a9
F src/vdbeaux.c 787f5f9d58f4c6f39294ed06909ba602d1a402e6
F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90
F src/vdbemem.c ae38a0d35ae71cf604381a887c170466ba518090
@@ -1307,7 +1307,7 @@ F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a
F test/without_rowid5.test 61256715b686359df48ca1742db50cc7e3e7b862
F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f
F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda
F test/zeroblob.test 202dbc81129a4a1509f829384b2b8aaf091635a9
F test/zeroblob.test de0bf437a28a0b46f25bf735a0b83f74d46256ed
F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac
F tool/build-all-msvc.bat 9058bd90a3c078a3d8c17d40e853aaa0f47885f4 x
F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367
@@ -1365,7 +1365,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 562687d9f56bf4bb0f5f07f97cbbb7649c81faf8
R 1786aea7f8e6749074e67e1af5c8c763
U drh
Z 01a0292cb698589e36de0afbd61cb525
P 4e3e516a42059c97f42a7eb59bdf5cded0ff843a
R bcc4b0d19f8b6f51dfb98e4327642a62
U dan
Z 5486cc6a4cbcc5894497bb04b4f0e89b
+1 -1
View File
@@ -1 +1 @@
4e3e516a42059c97f42a7eb59bdf5cded0ff843a
c6445b9fb4d7d1a8479436d7d183bad754a01615
+5 -5
View File
@@ -1122,17 +1122,17 @@ static void zeroblobFunc(
sqlite3_value **argv
){
i64 n;
int rc;
sqlite3 *db = sqlite3_context_db_handle(context);
assert( argc==1 );
UNUSED_PARAMETER(argc);
n = sqlite3_value_int64(argv[0]);
testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH] );
testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
sqlite3_result_error_toobig(context);
}else{
if( n<0 ) n = 0;
sqlite3_result_zeroblob(context, (int)n); /* IMP: R-00293-64994 */
if( n<0 ) n = 0;
rc = sqlite3_result_zeroblob64(context, n); /* IMP: R-00293-64994 */
if( rc ){
sqlite3_result_error_code(context, rc);
}
}
+3 -2
View File
@@ -4534,8 +4534,8 @@ typedef void (*sqlite3_destructor_type)(void*);
** to by the second parameter and which is N bytes long where N is the
** third parameter.
**
** ^The sqlite3_result_zeroblob() interfaces set the result of
** the application-defined function to be a BLOB containing all zero
** ^The sqlite3_result_zeroblob() and zeroblob64() interfaces set the result
** of the application-defined function to be a BLOB containing all zero
** bytes and N bytes in size, where N is the value of the 2nd parameter.
**
** ^The sqlite3_result_double() interface sets the result from
@@ -4651,6 +4651,7 @@ void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
void sqlite3_result_zeroblob(sqlite3_context*, int n);
int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
/*
** CAPI3REF: Define New Collating Sequences
+2
View File
@@ -270,6 +270,7 @@ struct sqlite3_api_routines {
/* Version 3.8.11 and later */
sqlite3_value *(*value_dup)(const sqlite3_value*);
void (*value_free)(sqlite3_value*);
int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
};
/*
@@ -503,6 +504,7 @@ struct sqlite3_api_routines {
/* Version 3.8.11 and later */
#define sqlite3_value_dup sqlite3_api->value_dup
#define sqlite3_value_free sqlite3_api->value_free
#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64
#endif /* SQLITE_CORE */
#ifndef SQLITE_CORE
+13 -1
View File
@@ -162,7 +162,10 @@ int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
const void *sqlite3_value_blob(sqlite3_value *pVal){
Mem *p = (Mem*)pVal;
if( p->flags & (MEM_Blob|MEM_Str) ){
if( sqlite3VdbeMemExpandBlob(p)!=SQLITE_OK ) return 0;
if( sqlite3VdbeMemExpandBlob(p)!=SQLITE_OK ){
assert( p->flags==MEM_Null && p->z==0 );
return 0;
}
p->flags |= MEM_Blob;
return p->n ? p->z : 0;
}else{
@@ -424,6 +427,15 @@ void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
}
int sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){
Mem *pOut = pCtx->pOut;
assert( sqlite3_mutex_held(pOut->db->mutex) );
if( n>pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
return SQLITE_TOOBIG;
}
sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n);
return SQLITE_OK;
}
void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
pCtx->isError = errCode;
pCtx->fErrorOrAux = 1;
+20
View File
@@ -17,6 +17,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix zeroblob
ifcapable !incrblob {
finish_test
@@ -267,6 +268,25 @@ do_test zeroblob-10.1 {
catchsql {INSERT INTO t10 VALUES(zeroblob(1e9),zeroblob(1e9),zeroblob(1e9))}
} {1 {string or blob too big}}
#-------------------------------------------------------------------------
## Test the zeroblob() function on its own with negative or oversized
## arguments.
##
do_execsql_test 11.0 {
SELECT length(zeroblob(-1444444444444444));
} {0}
do_catchsql_test 11.1 {
SELECT zeroblob(1025 * 1024 * 1024);
} {1 {string or blob too big}}
do_catchsql_test 11.2 {
SELECT quote(zeroblob(1025 * 1024 * 1024));
} {1 {string or blob too big}}
do_catchsql_test 11.3 {
SELECT quote(zeroblob(-1444444444444444));
} {0 X''}
do_catchsql_test 11.4 {
SELECT quote(test_zeroblob(-1));
} {0 X''}
test_restore_config_pagecache
finish_test