/ Check-in [d2a02737]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix an off-by-one error (really off-by-2 in this case) in the buffer resize logic of json1.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d2a027372a5a6efc0f9b6f605093d865ae1c6788
User & Date: drh 2015-09-19 11:57:26
Context
2015-09-19
12:04
Fix a documentation typo in sqlite3_bind_parameter_index(). No code changes. check-in: 650605a8 user: drh tags: trunk
11:57
Fix an off-by-one error (really off-by-2 in this case) in the buffer resize logic of json1. check-in: d2a02737 user: drh tags: trunk
03:07
Do not allow rowid in a UNIQUE or PRIMARY KEY constraint. (This restores the same behavior exhibited by all prior releases.) check-in: b1278301 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/misc/json1.c.

235
236
237
238
239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
  u32 i;
  if( (N+p->nUsed+2 >= p->nAlloc) && jsonGrow(p,N+2)!=0 ) return;
  p->zBuf[p->nUsed++] = '"';
  for(i=0; i<N; i++){
    char c = zIn[i];
    if( c=='"' || c=='\\' ){
      if( (p->nUsed+N+1-i > p->nAlloc) && jsonGrow(p,N+1-i)!=0 ) return;
      p->zBuf[p->nUsed++] = '\\';
    }
    p->zBuf[p->nUsed++] = c;
  }
  p->zBuf[p->nUsed++] = '"';

}

/*
** Append a function parameter value to the JSON string under 
** construction.
*/
static void jsonAppendValue(







|





>







235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
  u32 i;
  if( (N+p->nUsed+2 >= p->nAlloc) && jsonGrow(p,N+2)!=0 ) return;
  p->zBuf[p->nUsed++] = '"';
  for(i=0; i<N; i++){
    char c = zIn[i];
    if( c=='"' || c=='\\' ){
      if( (p->nUsed+N+3-i > p->nAlloc) && jsonGrow(p,N+3-i)!=0 ) return;
      p->zBuf[p->nUsed++] = '\\';
    }
    p->zBuf[p->nUsed++] = c;
  }
  p->zBuf[p->nUsed++] = '"';
  assert( p->nUsed<p->nAlloc );
}

/*
** Append a function parameter value to the JSON string under 
** construction.
*/
static void jsonAppendValue(

Changes to test/json102.test.

280
281
282
283
284
285
286
287









288

#-------------------------------------------------------------------------
# Test that json_valid() correctly identifies non-ascii range 
# characters as non-whitespace.
#
do_execsql_test json102-1201 { SELECT json_valid(char(32)  || '"xyz"') } 1
do_execsql_test json102-1202 { SELECT json_valid(char(200) || '"xyz"') } 0










finish_test








>
>
>
>
>
>
>
>
>

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

#-------------------------------------------------------------------------
# Test that json_valid() correctly identifies non-ascii range 
# characters as non-whitespace.
#
do_execsql_test json102-1201 { SELECT json_valid(char(32)  || '"xyz"') } 1
do_execsql_test json102-1202 { SELECT json_valid(char(200) || '"xyz"') } 0

# Off-by-one error in jsonAppendString()
#
for {set i 0} {$i<100} {incr i} {
  set str abcdef[string repeat \" [expr {$i+50}]]uvwxyz
  do_test json102-[format %d [expr {$i+1300}]] {
    db eval {SELECT json_extract(json_array($::str),'$[0]')==$::str}
  } {1}
}

finish_test