From: drh <> Date: Sat, 13 Sep 2025 17:53:14 +0000 (+0000) Subject: Enhance the integerValue() routine in the CLI so that when its text input X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=96455af9503094c862c1bf781d3c8d63883b707e;p=thirdparty%2Fsqlite.git Enhance the integerValue() routine in the CLI so that when its text input specifies an out-of-range integer, the routine returns the nearest integer that is representable as 64-bit twos-complement. FossilOrigin-Name: 5d50279fcb66b479e76586b729f36d389b28940476ff70d61b0066a5d5d3ad0c --- diff --git a/manifest b/manifest index 3cdeb76419..aecda78b1e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\sTODO\sregarding\sreplacing\sthe\sinternal\ssqlite3__wasm_db_error()\swith\sthe\snew\s[34eda113c8819d\s|\ssqlite3_set_errmsg()],\swhich\sserves\sthe\ssame\srole. -D 2025-09-12T17:36:23.257 +C Enhance\sthe\sintegerValue()\sroutine\sin\sthe\sCLI\sso\sthat\swhen\sits\stext\sinput\nspecifies\san\sout-of-range\sinteger,\sthe\sroutine\sreturns\sthe\snearest\sinteger\nthat\sis\srepresentable\sas\s64-bit\stwos-complement. +D 2025-09-13T17:53:14.695 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -742,7 +742,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c f8d1d011aba0964ff1bdccd049d4d2c2fec217efd90d202a4bb775e926b2c25d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c b95181711d59c36d9789e67f76c4cfec64b99f9629a50be5e6566e117b87d957 -F src/shell.c.in c309e6e95b4de2be9dd0fbe4d40f729199a85bcc54d66759a0aef3b3e6504b22 +F src/shell.c.in 694e67b4d8c09a27b5d55696973b0511974a9337906222006529989e40218156 F src/sqlite.h.in 5732519a2acb09066032ceac21f25996eb3f28f807a4468e30633c7c70faae1c F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 3f0c4ed6934e7309a61c6f3c30f70a30a5b869f785bb3d9f721a36c5e4359126 @@ -2174,8 +2174,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e34eda113c8819df46c139ccf749b686c8bfdd399f59345c6d6be3736bdf97cb -R 7ce068fa579e2511d000a3c5b6dbc6d3 -U stephan -Z 7547c1657724e40779150571322f7ca2 +P ead8a3a94e0f349bcdced6a62af0349b0b7b731137c8d33e2ef0e7eecd107c1f +R b1fa16bbc1f849c3ca9135d719410333 +U drh +Z a6d11ba07cbae9bdd6ab42dfdcc5fd47 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 15f2286e99..c2f8fe9761 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ead8a3a94e0f349bcdced6a62af0349b0b7b731137c8d33e2ef0e7eecd107c1f +5d50279fcb66b479e76586b729f36d389b28940476ff70d61b0066a5d5d3ad0c diff --git a/src/shell.c.in b/src/shell.c.in index 528474e638..fc496f5194 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1070,10 +1070,14 @@ static int hexDigitValue(char c){ /* ** Interpret zArg as an integer value, possibly with suffixes. +** +** If the value specified by zArg is outside the range of values that +** can be represented using a 64-bit twos-complement integer, then return +** the nearest representable value. */ static sqlite3_int64 integerValue(const char *zArg){ - sqlite3_int64 v = 0; - static const struct { char *zSuffix; int iMult; } aMult[] = { + sqlite3_uint64 v = 0; + static const struct { char *zSuffix; unsigned int iMult; } aMult[] = { { "KiB", 1024 }, { "MiB", 1024*1024 }, { "GiB", 1024*1024*1024 }, @@ -1096,22 +1100,30 @@ static sqlite3_int64 integerValue(const char *zArg){ int x; zArg += 2; while( (x = hexDigitValue(zArg[0]))>=0 ){ + if( v > 0x0fffffffffffffffULL ) goto integer_overflow; v = (v<<4) + x; zArg++; } }else{ while( IsDigit(zArg[0]) ){ - v = v*10 + zArg[0] - '0'; + if( v>=922337203685477580 ){ + if( v>922337203685477580 || zArg[0]>='8' ) goto integer_overflow; + } + v = v*10 + (zArg[0] - '0'); zArg++; } } for(i=0; i0x7fffffffffffffffULL ) goto integer_overflow; + return isNeg? -(sqlite3_int64)v : (sqlite3_int64)v; +integer_overflow: + return isNeg ? 0x8000000000000000LL : 0x7fffffffffffffffLL; } /*