SQLite

Check-in [495fb41626]
Login

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

Overview
Comment:Improved test coverage in date.c. Report an error if a malloc fails within strftime(). (CVS 4721)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 495fb41626dfbfbeeb748675b9476a4f7cec6c7a
User & Date: drh 2008-01-17 20:26:47.000
Context
2008-01-17
22:27
Test coverage for date.c. (CVS 4722) (check-in: a676f949b6 user: drh tags: trunk)
20:26
Improved test coverage in date.c. Report an error if a malloc fails within strftime(). (CVS 4721) (check-in: 495fb41626 user: drh tags: trunk)
17:27
Remove unused p4 element from the {quote: VdbeOpList} object. (CVS 4720) (check-in: 1c37d7b69b user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/date.c.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This file contains the C functions that implement date and time
** functions for SQLite.  
**
** There is only one exported symbol in this file - the function
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.73 2007/09/12 17:01:45 danielk1977 Exp $
**
** SQLite processes all times and dates as Julian Day numbers.  The
** dates and times are stored as the number of days since noon
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
** calendar system. 
**
** 1970-01-01 00:00:00 is JD 2440587.5







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This file contains the C functions that implement date and time
** functions for SQLite.  
**
** There is only one exported symbol in this file - the function
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.74 2008/01/17 20:26:47 drh Exp $
**
** SQLite processes all times and dates as Julian Day numbers.  The
** dates and times are stored as the number of days since noon
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
** calendar system. 
**
** 1970-01-01 00:00:00 is JD 2440587.5
823
824
825
826
827
828
829
830



831
832
833
834
835
836
837
  if( n<sizeof(zBuf) ){
    z = zBuf;
  }else if( n>SQLITE_MAX_LENGTH ){
    sqlite3_result_error_toobig(context);
    return;
  }else{
    z = sqlite3_malloc( n );
    if( z==0 ) return;



  }
  computeJD(&x);
  computeYMD_HMS(&x);
  for(i=j=0; zFmt[i]; i++){
    if( zFmt[i]!='%' ){
      z[j++] = zFmt[i];
    }else{







|
>
>
>







823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
  if( n<sizeof(zBuf) ){
    z = zBuf;
  }else if( n>SQLITE_MAX_LENGTH ){
    sqlite3_result_error_toobig(context);
    return;
  }else{
    z = sqlite3_malloc( n );
    if( z==0 ){
      sqlite3_result_error_nomem(context);
      return;
    }
  }
  computeJD(&x);
  computeYMD_HMS(&x);
  for(i=j=0; zFmt[i]; i++){
    if( zFmt[i]!='%' ){
      z[j++] = zFmt[i];
    }else{
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
        case 'w':  z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break;
        case 'Y':  sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=strlen(&z[j]);break;
        case '%':  z[j++] = '%'; break;
      }
    }
  }
  z[j] = 0;
  sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
  if( z!=zBuf ){
    sqlite3_free(z);
  }
}

/*
** current_time()
**
** This function returns the same value as time('now').
*/







|
<
|
<







886
887
888
889
890
891
892
893

894

895
896
897
898
899
900
901
        case 'w':  z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break;
        case 'Y':  sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=strlen(&z[j]);break;
        case '%':  z[j++] = '%'; break;
      }
    }
  }
  z[j] = 0;
  sqlite3_result_text(context, z, -1,

                      z==zBuf ? SQLITE_TRANSIENT : sqlite3_free);

}

/*
** current_time()
**
** This function returns the same value as time('now').
*/
Changes to test/mallocB.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file contains additional out-of-memory checks (see malloc.tcl).
# These were all discovered by fuzzy generation of SQL. Apart from
# that they have little in common.
#
#
# $Id: mallocB.test,v 1.6 2007/09/12 17:01:45 danielk1977 Exp $

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

# Only run these tests if memory debugging is turned on.
#







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file contains additional out-of-memory checks (see malloc.tcl).
# These were all discovered by fuzzy generation of SQL. Apart from
# that they have little in common.
#
#
# $Id: mallocB.test,v 1.7 2008/01/17 20:26:47 drh Exp $

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

# Only run these tests if memory debugging is turned on.
#
39
40
41
42
43
44
45
46




47
# The following test checks that there are no resource leaks following a
# malloc() failure in sqlite3_set_auxdata().
#
# Note: This problem was not discovered by fuzzy generation of SQL. Not
# that it really matters.
#
do_malloc_test mallocB-6 -sqlbody { SELECT test_auxdata('hello world'); }





finish_test








>
>
>
>

39
40
41
42
43
44
45
46
47
48
49
50
51
# The following test checks that there are no resource leaks following a
# malloc() failure in sqlite3_set_auxdata().
#
# Note: This problem was not discovered by fuzzy generation of SQL. Not
# that it really matters.
#
do_malloc_test mallocB-6 -sqlbody { SELECT test_auxdata('hello world'); }

do_malloc_test mallocB-7 -sqlbody {
  SELECT strftime(hex(randomblob(50)) || '%Y', 'now')
}

finish_test
Changes to test/sqllimits1.test.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file contains tests to verify that the limits defined in
# sqlite source file limits.h are enforced.
#
# $Id: sqllimits1.test,v 1.21 2007/12/17 16:20:07 drh Exp $

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

# Test organization:
#
#     sqllimits-1.*:  SQLITE_MAX_LENGTH







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file contains tests to verify that the limits defined in
# sqlite source file limits.h are enforced.
#
# $Id: sqllimits1.test,v 1.22 2008/01/17 20:26:47 drh Exp $

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

# Test organization:
#
#     sqllimits-1.*:  SQLITE_MAX_LENGTH
152
153
154
155
156
157
158
159
160











161
162
163
164
165
166
167
set blobvalue [string repeat 41 $::SQLITE_MAX_LENGTH]
do_test sqllimits-1.18 {
  catchsql "SELECT x'$blobvalue'"
} [list 0 $strvalue]
do_test sqllimits-1.19 {
  catchsql "SELECT '41$blobvalue'"
} [list 1 {string or blob too big}]
unset strvalue
unset blobvalue












#--------------------------------------------------------------------
# Test cases sqllimits-2.* test that the SQLITE_MAX_SQL_LENGTH limit
# is enforced.
#
do_test sqllimits-2.1 {
  set ::SQLITE_MAX_SQL_LENGTH 50000







<

>
>
>
>
>
>
>
>
>
>
>







152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
set blobvalue [string repeat 41 $::SQLITE_MAX_LENGTH]
do_test sqllimits-1.18 {
  catchsql "SELECT x'$blobvalue'"
} [list 0 $strvalue]
do_test sqllimits-1.19 {
  catchsql "SELECT '41$blobvalue'"
} [list 1 {string or blob too big}]

unset blobvalue

ifcapable datetime {
  set strvalue [string repeat D [expr {$SQLITE_MAX_LENGTH-12}]]
  do_test sqllimits-1.20 {
    catchsql {SELECT strftime('%Y ' || $::strvalue, '2008-01-02')}
  } [list 0 [list "2008 $strvalue"]]
  do_test sqllimits-1.21 {
    catchsql {SELECT strftime('%Y-%m-%d ' || $::strvalue, '2008-01-02')}
  } {1 {string or blob too big}}
}
unset strvalue

#--------------------------------------------------------------------
# Test cases sqllimits-2.* test that the SQLITE_MAX_SQL_LENGTH limit
# is enforced.
#
do_test sqllimits-2.1 {
  set ::SQLITE_MAX_SQL_LENGTH 50000