aboutsummaryrefslogtreecommitdiff
path: root/src/func.c
diff options
context:
space:
mode:
authordan <Dan Kennedy>2024-12-26 14:40:11 +0000
committerdan <Dan Kennedy>2024-12-26 14:40:11 +0000
commit4e3b6a14fdcb2e09327348bcf9be3c47db43a4cf (patch)
tree29b472b6926a653671c07a0a598511d3ced9d570 /src/func.c
parentce50282c3bf662c1e12d066bff869c53532a3d74 (diff)
parent9591d3fe93936533c8c3b0dc4d025ac999539e11 (diff)
downloadsqlite-4e3b6a14fdcb2e09327348bcf9be3c47db43a4cf.tar.gz
sqlite-4e3b6a14fdcb2e09327348bcf9be3c47db43a4cf.zip
Merge trunk changes into this branch.
FossilOrigin-Name: 3e2893097c59820def88bb4739189c9c9a4f70a98a0a72b81959658f069715f6
Diffstat (limited to 'src/func.c')
-rw-r--r--src/func.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/func.c b/src/func.c
index 2d25803e0..a4b72ecc4 100644
--- a/src/func.c
+++ b/src/func.c
@@ -363,7 +363,7 @@ static void substrFunc(
return;
}
p0type = sqlite3_value_type(argv[0]);
- p1 = sqlite3_value_int(argv[1]);
+ p1 = sqlite3_value_int64(argv[1]);
if( p0type==SQLITE_BLOB ){
len = sqlite3_value_bytes(argv[0]);
z = sqlite3_value_blob(argv[0]);
@@ -388,7 +388,7 @@ static void substrFunc(
if( p1==0 ) p1 = 1; /* <rdar://problem/6778339> */
#endif
if( argc==3 ){
- p2 = sqlite3_value_int(argv[2]);
+ p2 = sqlite3_value_int64(argv[2]);
if( p2<0 ){
p2 = -p2;
negP2 = 1;
@@ -427,9 +427,11 @@ static void substrFunc(
sqlite3_result_text64(context, (char*)z, z2-z, SQLITE_TRANSIENT,
SQLITE_UTF8);
}else{
- if( p1+p2>len ){
+ if( p1>=len ){
+ p1 = p2 = 0;
+ }else if( p2>len-p1 ){
p2 = len-p1;
- if( p2<0 ) p2 = 0;
+ assert( p2>0 );
}
sqlite3_result_blob64(context, (char*)&z[p1], (u64)p2, SQLITE_TRANSIENT);
}
@@ -440,13 +442,13 @@ static void substrFunc(
*/
#ifndef SQLITE_OMIT_FLOATING_POINT
static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
- int n = 0;
+ i64 n = 0;
double r;
char *zBuf;
assert( argc==1 || argc==2 );
if( argc==2 ){
if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return;
- n = sqlite3_value_int(argv[1]);
+ n = sqlite3_value_int64(argv[1]);
if( n>30 ) n = 30;
if( n<0 ) n = 0;
}
@@ -461,7 +463,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
}else if( n==0 ){
r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5)));
}else{
- zBuf = sqlite3_mprintf("%!.*f",n,r);
+ zBuf = sqlite3_mprintf("%!.*f",(int)n,r);
if( zBuf==0 ){
sqlite3_result_error_nomem(context);
return;