SQLite

Check-in [cd2e7f6c0f]
Login

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

Overview
Comment:Check-in (6230) introduced a bugs in SUBSTR() which was caught by the fuzz tester. Fixed by this check-in. Related to ticket #3628. (CVS 6234)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: cd2e7f6c0fe4c0c648f8ca21388ab0769164f5ef
User & Date: drh 2009-02-03 13:10:54.000
Context
2009-02-03
13:19
Fix a problem in check-in (6226) which could cause an assertion fault following a malloc failure. The prior check-in was for ticket #3624. (CVS 6235) (check-in: 1ffe44e9d6 user: drh tags: trunk)
13:10
Check-in (6230) introduced a bugs in SUBSTR() which was caught by the fuzz tester. Fixed by this check-in. Related to ticket #3628. (CVS 6234) (check-in: cd2e7f6c0f user: drh tags: trunk)
2009-02-02
21:57
Make group_concat() a 1- or 2-value function, as the documentation says it should be. Use the md5sum() function to verify ticket #3179, not group_concat(). This undoes the ill-advised group_concat() change of check-in (5233). (CVS 6233) (check-in: f2ae82c4d4 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/func.c.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.218 2009/02/02 21:57:05 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"

/*







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.219 2009/02/03 13:10:54 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"

/*
220
221
222
223
224
225
226

227
228
229
230
231
232
233
      p2 += p1;
      p1 = 0;
    }
  }
  assert( p1>=0 && p2>=0 );
  if( p1+p2>len ){
    p2 = len-p1;

  }
  if( p0type!=SQLITE_BLOB ){
    while( *z && p1 ){
      SQLITE_SKIP_UTF8(z);
      p1--;
    }
    for(z2=z; *z2 && p2; p2--){







>







220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
      p2 += p1;
      p1 = 0;
    }
  }
  assert( p1>=0 && p2>=0 );
  if( p1+p2>len ){
    p2 = len-p1;
    if( p2<0 ) p2 = 0;
  }
  if( p0type!=SQLITE_BLOB ){
    while( *z && p1 ){
      SQLITE_SKIP_UTF8(z);
      p1--;
    }
    for(z2=z; *z2 && p2; p2--){
Changes to test/substr.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2007 May 14
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing the built-in SUBSTR() functions.
#
# $Id: substr.test,v 1.6 2009/02/02 16:32:55 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !tclvar {
  finish_test
  return













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2007 May 14
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing the built-in SUBSTR() functions.
#
# $Id: substr.test,v 1.7 2009/02/03 13:10:54 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !tclvar {
  finish_test
  return
74
75
76
77
78
79
80


81
82
83
84
85
86
87
substr-test 1.10 abcdefg -100 98 abcde
substr-test 1.11 abcdefg 5 -1 d
substr-test 1.12 abcdefg 5 -4 abcd
substr-test 1.13 abcdefg 5 -5 abcd
substr-test 1.14 abcdefg -5 -1 b
substr-test 1.15 abcdefg -5 -2 ab
substr-test 1.16 abcdefg -5 -3 ab



# Make sure NULL is returned if any parameter is NULL
#
do_test substr-1.90 {
  db eval {SELECT ifnull(substr(NULL,1,1),'nil')}
} nil
do_test substr-1.91 {







>
>







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
substr-test 1.10 abcdefg -100 98 abcde
substr-test 1.11 abcdefg 5 -1 d
substr-test 1.12 abcdefg 5 -4 abcd
substr-test 1.13 abcdefg 5 -5 abcd
substr-test 1.14 abcdefg -5 -1 b
substr-test 1.15 abcdefg -5 -2 ab
substr-test 1.16 abcdefg -5 -3 ab
substr-test 1.17 abcdefg 100 200 {}
substr-test 1.18 abcdefg 200 100 {}

# Make sure NULL is returned if any parameter is NULL
#
do_test substr-1.90 {
  db eval {SELECT ifnull(substr(NULL,1,1),'nil')}
} nil
do_test substr-1.91 {
114
115
116
117
118
119
120


121
122
123
124
125
126
127
subblob-test 3.4 61626364656667 1 100 61626364656667
subblob-test 3.5 61626364656667 0 2 61
subblob-test 3.6 61626364656667 -1 1 67
subblob-test 3.7 61626364656667 -1 10 67
subblob-test 3.8 61626364656667 -5 3 636465
subblob-test 3.9 61626364656667 -7 3 616263
subblob-test 3.10 61626364656667 -100 98 6162636465



# If these blobs were strings, then they would contain multi-byte
# characters.  But since they are blobs, the substr indices refer
# to bytes.
#
subblob-test 4.1 61E188B462E28D8563E3919663 1 1 61
subblob-test 4.2 61E188B462E28D8563E3919663 2 1 E1







>
>







116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
subblob-test 3.4 61626364656667 1 100 61626364656667
subblob-test 3.5 61626364656667 0 2 61
subblob-test 3.6 61626364656667 -1 1 67
subblob-test 3.7 61626364656667 -1 10 67
subblob-test 3.8 61626364656667 -5 3 636465
subblob-test 3.9 61626364656667 -7 3 616263
subblob-test 3.10 61626364656667 -100 98 6162636465
subblob-test 3.11 61626364656667 100 200 {}
subblob-test 3.12 61626364656667 200 100 {}

# If these blobs were strings, then they would contain multi-byte
# characters.  But since they are blobs, the substr indices refer
# to bytes.
#
subblob-test 4.1 61E188B462E28D8563E3919663 1 1 61
subblob-test 4.2 61E188B462E28D8563E3919663 2 1 E1