diff options
author | drh <> | 2023-07-26 11:00:47 +0000 |
---|---|---|
committer | drh <> | 2023-07-26 11:00:47 +0000 |
commit | 9a184daad3991239595b007e1bb2b1167aeb2cac (patch) | |
tree | 16bd4519fa829df379b51fcb76ce2b8246f67621 /src/json.c | |
parent | a757026c5e8ba7d61d1b178ab98178d3264c880f (diff) | |
download | sqlite-9a184daad3991239595b007e1bb2b1167aeb2cac.tar.gz sqlite-9a184daad3991239595b007e1bb2b1167aeb2cac.zip |
Fix jsonForceRCStr() to also add the NULL terminator.
FossilOrigin-Name: 134b01f37f8f741d7f7b7eda81384695d1cbe4c39751d87f08832d5c9afdcef2
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/json.c b/src/json.c index a4a3e65c9..3ad5af659 100644 --- a/src/json.c +++ b/src/json.c @@ -248,16 +248,6 @@ static int jsonGrow(JsonString *p, u32 N){ return SQLITE_OK; } -/* Try to force the string to be an RCStr string, rather than a -** static string. Return true on success. The only reason this -** might fail is due to an OOM fault. -*/ -static int jsonForceRCStr(JsonString *p){ - if( p->bStatic==0 ) return 1; - jsonGrow(p, p->nAlloc+1); - return p->bStatic==0; -} - /* Append N bytes from zIn onto the end of the JsonString string. */ static SQLITE_NOINLINE void jsonAppendExpand( @@ -315,6 +305,22 @@ static void jsonAppendChar(JsonString *p, char c){ } } +/* Try to force the string to be a zero-terminated RCStr string. +** +** Return true on success. Return false if an OOM prevents this +** from happening. +*/ +static int jsonForceRCStr(JsonString *p){ + jsonAppendChar(p, 0); + if( p->bErr ) return 0; + p->nUsed--; + if( p->bStatic==0 ) return 1; + p->nAlloc = 0; + jsonGrow(p, p->nUsed); + return p->bStatic==0; +} + + /* Append a comma separator to the output buffer, if the previous ** character is not '[' or '{'. */ @@ -798,8 +804,6 @@ static void jsonReturnJson( jsonInit(&s, pCtx); jsonRenderNode(pParse, pNode, &s); if( bGenerateAlt && pParse->zAlt==0 && jsonForceRCStr(&s) ){ - jsonAppendChar(&s, 0); - s.nUsed--; pParse->zAlt = sqlite3RCStrRef(s.zBuf); pParse->nAlt = s.nUsed; } |