From: drh <> Date: Sun, 3 Dec 2023 00:51:30 +0000 (+0000) Subject: Minor code changes for consistency and to simplify testing. X-Git-Tag: version-3.45.0~116^2~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eb18ae3089ac409ed7c0bd943a993ea8b357c2f5;p=thirdparty%2Fsqlite.git Minor code changes for consistency and to simplify testing. FossilOrigin-Name: df272bd837910ad9e03e222716a1201a601399664365f1dcf73d5932372518ed --- diff --git a/manifest b/manifest index 95a05c007f..0746333f7a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Implement\sstrict\sJSONB\schecking\sin\sthe\sjson_valid()\sfunction. -D 2023-12-02T21:39:34.516 +C Minor\scode\schanges\sfor\sconsistency\sand\sto\ssimplify\stesting. +D 2023-12-03T00:51:30.732 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -688,7 +688,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c fd321d1ab2d6f42354bd2ff7bc4974ab8dd9eee977e4e8e137cf1360873ef052 +F src/json.c 9a79d32ad7df0f37aaca77a78278af177b7c898f719f7f3c1beb6626cf0cd88e F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 1b89f3de98d1b59fec5bac1d66d6ece21f703821b8eaa0d53d9604c35309f6f9 @@ -2145,8 +2145,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 419652c0c82980bd043584dcd2976f91dfff7b926b216d597698299850b855c0 -R ed8c7ad5ad50d0c7dab9c9a4109db3da +P 0f26d38880fcbc207abcc94dbc170a7428bab1b4f0b7731aaf5bee0224000994 +R 66de56e0a2d95958c6880cf67a24bb7b U drh -Z 50662e1c3dbad4c9b4aaea32a805ad55 +Z 5f7e6173dda49cfc3454a89f079d029d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c4f20a42ae..8eca6d0777 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0f26d38880fcbc207abcc94dbc170a7428bab1b4f0b7731aaf5bee0224000994 \ No newline at end of file +df272bd837910ad9e03e222716a1201a601399664365f1dcf73d5932372518ed \ No newline at end of file diff --git a/src/json.c b/src/json.c index ae6458cd59..a35306b62e 100644 --- a/src/json.c +++ b/src/json.c @@ -534,7 +534,7 @@ static void jsonAppendRaw(JsonString *p, const char *zIn, u32 N){ } } static void jsonAppendRawNZ(JsonString *p, const char *zIn, u32 N){ - if( N==0 ) return; + assert( N>0 ); if( N+p->nUsed >= p->nAlloc ){ jsonStringExpandAndAppend(p,zIn,N); }else{ @@ -572,9 +572,8 @@ static void jsonAppendChar(JsonString *p, char c){ /* Make sure there is a zero terminator on p->zBuf[] */ static void jsonStringTerminate(JsonString *p){ - if( p->nUsednAlloc || jsonStringGrow(p,1) ){ - p->zBuf[p->nUsed] = 0; - } + jsonAppendChar(p, 0); + p->nUsed--; } /* Try to force the string to be a zero-terminated RCStr string. In other @@ -991,24 +990,6 @@ static const struct NanInfName { }; -/* -** Compute the text of an error in JSON path syntax. -** -** If ctx is not NULL then push the error message into ctx and return NULL. -* If ctx is NULL, then return the text of the error message. -*/ -static char *jsonPathSyntaxError(const char *zErr, sqlite3_context *ctx){ - char *zMsg = sqlite3_mprintf("JSON path error near '%q'", zErr); - if( ctx==0 ) return zMsg; - if( zMsg==0 ){ - sqlite3_result_error_nomem(ctx); - }else{ - sqlite3_result_error(ctx, zMsg, -1); - sqlite3_free(zMsg); - } - return 0; -} - /* ** Report the wrong number of arguments for json_insert(), json_replace() ** or json_set(). @@ -2659,15 +2640,19 @@ static int jsonFunctionArgToBlob( /* ** Generate a bad path error. +** +** If ctx is not NULL then push the error message into ctx and return NULL. +** If ctx is NULL, then return the text of the error message. */ -static void jsonBadPathError( +static char *jsonBadPathError( sqlite3_context *ctx, /* The function call containing the error */ const char *zPath /* The path with the problem */ ){ - sqlite3 *db = sqlite3_context_db_handle(ctx); - char *zMsg = sqlite3MPrintf(db, "bad JSON path: %Q", zPath); + char *zMsg = sqlite3_mprintf("bad JSON path: %Q", zPath); + if( ctx==0 ) return zMsg; sqlite3_result_error(ctx, zMsg, -1); - sqlite3DbFree(db, zMsg); + sqlite3_free(zMsg); + return 0; } /* argv[0] is a BLOB that seems likely to be a JSONB. Subsequent @@ -3287,7 +3272,6 @@ static void jsonExtractFunc( }else if( zPath[0]!='[' ){ jsonAppendRawNZ(&jx, ".", 1); jsonAppendRaw(&jx, zPath, nPath); - jsonAppendChar(&jx, 0); }else{ jsonAppendRaw(&jx, zPath, nPath); } @@ -3685,7 +3669,7 @@ static void jsonRemoveFunc( json_remove_patherror: jsonParseFree(p); - jsonPathSyntaxError(zPath, ctx); + jsonBadPathError(ctx, zPath); return; json_remove_return_null: @@ -4689,7 +4673,7 @@ static int jsonEachFilter( if( zRoot==0 ) return SQLITE_OK; if( zRoot[0]!='$' ){ sqlite3_free(cur->pVtab->zErrMsg); - cur->pVtab->zErrMsg = jsonPathSyntaxError(zRoot, 0); + cur->pVtab->zErrMsg = jsonBadPathError(0, zRoot); jsonEachCursorReset(p); return cur->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM; } @@ -4707,7 +4691,7 @@ static int jsonEachFilter( return SQLITE_OK; } sqlite3_free(cur->pVtab->zErrMsg); - cur->pVtab->zErrMsg = jsonPathSyntaxError(zRoot, 0); + cur->pVtab->zErrMsg = jsonBadPathError(0, zRoot); jsonEachCursorReset(p); return cur->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM; }