]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Resolve a valgrind-reported error in ext/wasm/c-pp-lite.c caused by successful exit...
authorstephan <stephan@noemail.net>
Wed, 15 Oct 2025 23:13:50 +0000 (23:13 +0000)
committerstephan <stephan@noemail.net>
Wed, 15 Oct 2025 23:13:50 +0000 (23:13 +0000)
FossilOrigin-Name: 7801c7225a18ccb2216b01663b30e3eb90a961e3d165af73f964c515b74fe745

ext/wasm/c-pp-lite.c
ext/wasm/tester1.c-pp.js
manifest
manifest.uuid

index 53a3a28cb3933e5baf99e8abb9a820abe8c9899c..acb64df6541aab8465a937b008eba451b5763577 100644 (file)
@@ -657,7 +657,6 @@ static void CmppLevel_pop(CmppTokenizer * const t);
 */
 static CmppLevel * CmppLevel_get(CmppTokenizer * const t);
 
-#define CMPPLEVEL_GET
 /*
 ** Policies for how to handle undefined @tokens@ when performing
 ** content filtering.
@@ -1101,6 +1100,7 @@ static void db_define_add_file(const char * zKey){
              kvp.v.z ? kvp.v.z : ""));
 }
 
+#define ustr_c(X) ((unsigned char const *)X)
 
 static inline unsigned int cmpp_strlen(char const *z, int n){
   return n<0 ? (int)strlen(z) : (unsigned)n;
@@ -1284,9 +1284,11 @@ void g_FileWrapper_close(FileWrapper *fp){
 }
 
 static void g_cleanup(int bCloseFileChain){
+  if( g.db ){
 #define E(N,S) sqlite3_finalize(g.stmt.N); g.stmt.N = 0;
   GStmt_map(E)
 #undef E
+  }
   if( bCloseFileChain ){
     FileWrapper * fpNext = 0;
     for( FileWrapper * fp=g.pFiles; fp; fp=fpNext ){
@@ -1296,7 +1298,10 @@ static void g_cleanup(int bCloseFileChain){
     }
   }
   FileWrapper_close(&g.out);
-  if(g.db) sqlite3_close(g.db);
+  if(g.db){
+    sqlite3_close(g.db);
+    g.db = 0;
+  }
 }
 
 static void cmpp_atexit(void){
@@ -1449,7 +1454,11 @@ static void cmpp_t_out_expand(CmppTokenizer * const t,
                               unsigned int n);
 
 static inline int cmpp__isspace(int ch){
-  return ' '==ch || '\n'==ch || '\t'==ch || '\r'==ch;
+  return ' '==ch || '\t'==ch;
+}
+
+static inline unsigned cmpp__strlenu(unsigned char const *z, int n){
+  return n<0 ? (unsigned)strlen((char const *)z) : (unsigned)n;
 }
 
 static inline void cmpp__skip_space_c( unsigned char const **p,
@@ -1493,27 +1502,52 @@ int CmppTokenizer__delim_search(CmppTokenizer * const t){
     cmpp_t_out_expand(t, zLeft, (unsigned)(z-zLeft)); \
   } zLeft = z
   while(z < zEnd){
-    size_t const nNl = strcspn((char const *)z, "\n");
-    unsigned char const * const zNl = (z + nNl > zEnd ? zEnd : z + nNl);
-    if( nNl >= CmppArgs_BufSize /* too long */
+    size_t nNlTotal = 0;
+    unsigned char const * zNl;
+    size_t nNl2 = strcspn((char const *)z, "\n");
+    zNl = (z + nNl2 >= zEnd ? zEnd : z + nNl2);
+    if( nNl2 >= CmppArgs_BufSize /* too long */
         //|| '\n'!=(char)*zNl   /* end of input */
         /* ^^^ we have to accept a missing trailing EOL for the
            sake of -e scripts. */
     ){
+      /* we'd like to error out here, but only if we know we're
+         reading reading a directive line. */
       ++t->lineNo;
       z = zNl + 1;
       tflush;
       continue;
     }
+    nNlTotal += nNl2;
     assert( '\n'==*zNl || !*zNl );
-    //g_stderr("input: zNl=%d z=<<<%.*s>>>\n", (int)*zNl, (zNl-z), z);
+    assert( '\n'==*zNl || zNl==zEnd );
+    //g_stderr("input: zNl=%d z=<<<%.*s>>>", (int)*zNl, (zNl-z), z);
     unsigned char const * const zBOL = z;
     cmpp__skip_space_c(&z, zNl);
     if( z+nD < zNl && 0==memcmp(z, zD, nD) ){
+      /* Found a directive delimiter. */
       if( zBOL!=z ){
-        /* Do not emit space which preceeds a delimiter */
+        /* Do not emit space from the same line which preceeds a
+           delimiter */
         zLeft = z;
       }
+      while( zNl>z && zNl<zEnd
+             && '\n'==*zNl && '\\'==zNl[-1] ){
+        /* Backslash-escaped newline: extend the token
+           to consume it all. */
+        ++t->lineNo;
+        ++zNl;
+        nNl2 = strcspn((char const *)zNl, "\n");
+        if( !nNl2 ) break;
+        nNlTotal += nNl2;
+        zNl += nNl2;
+      }
+      assert( zNl<=zEnd && "Else our input was not NUL-terminated");
+      if( nNlTotal >= CmppArgs_BufSize ){
+        fatal("Directive line is too long (%u)",
+              (unsigned)(zNl-z));
+        break;
+      }
       tflush;
       t->token.zBegin = z + nD;
       t->token.zEnd = zNl;
@@ -1521,14 +1555,16 @@ int CmppTokenizer__delim_search(CmppTokenizer * const t){
       t->token.ttype = TT_Line;
       t->token.lineNo = t->lineNo++;
       t->zPos = t->token.zEnd + 1;
-
-      //g_stderr("token=%.*s\n", (zNl - t->token.zBegin), t->token.zBegin);
+      if( 0 ){
+        g_stderr("token=<<%.*s>>", (t->token.zEnd - t->token.zBegin),
+                 t->token.zBegin);
+      }
       return 1;
     }
     z = zNl+1;
     ++t->lineNo;
     tflush;
-    //g_stderr0("line #%d no match\n",(int)t->lineNO);
+    //g_stderr("line #%d no match\n",(int)t->lineNo);
   }
   tflush;
   t->zPos = z;
@@ -2379,31 +2415,38 @@ void cmpp_process_keyword(CmppTokenizer * const t){
   t->args.argc = 0;
 }
 
-void cmpp_process_file(const char * zName){
-  FileWrapper fw = FileWrapper_empty;
+void cmpp_process_string(const char * zName,
+                        unsigned char const * zIn,
+                        int nIn){
+  nIn = cmpp__strlenu(zIn, nIn);
+  if( !nIn ) return;
   CmppTokenizer const * const oldTok = g.tok;
   CmppTokenizer ct = CmppTokenizer_empty;
-  g.tok = &ct;
+  ct.zName = zName;
+  ct.zBegin = zIn;
+  ct.zEnd = zIn + nIn;
+  while(cmpp_next_keyword_line(&ct)){
+    cmpp_process_keyword(&ct);
+  }
+  if(0!=ct.level.ndx){
+    CmppLevel const * const lv = CmppLevel_get(&ct);
+    fatal("Input ended inside an unterminated nested construct "
+          "opened at [%s] line %u", zName, lv->token.lineNo);
+  }
+  CmppTokenizer_cleanup(&ct);
+  g.tok = oldTok;
+}
+
+void cmpp_process_file(const char * zName){
+  FileWrapper fw = FileWrapper_empty;
   FileWrapper_open(&fw, zName, "r");
   g_FileWrapper_link(&fw);
   FileWrapper_slurp(&fw);
   g_debug(1,("Read %u byte(s) from [%s]\n", fw.nContent, fw.zName));
   if( fw.zContent ){
-    ct.zName = zName;
-    ct.zBegin = fw.zContent;
-    ct.zEnd = fw.zContent + fw.nContent;
-    while(cmpp_next_keyword_line(&ct)){
-      cmpp_process_keyword(&ct);
-    }
+    cmpp_process_string(zName, fw.zContent, fw.nContent);
   }
   g_FileWrapper_close(&fw);
-  if(0!=ct.level.ndx){
-    CmppLevel * const lv = CmppLevel_get(&ct);
-    fatal("Input ended inside an unterminated nested construct"
-          "opened at [%s] line %u", zName, lv->token.lineNo);
-  }
-  CmppTokenizer_cleanup(&ct);
-  g.tok = oldTok;
 }
 
 
@@ -2542,6 +2585,9 @@ int main(int argc, char const * const * argv){
 #define ISFLAG(X) else if(M(X))
 #define ISFLAG2(X,Y) else if(M(X) || M(Y))
 #define NOVAL if( zVal ) fatal("Unexpected value for %s", zArg)
+#define g_out_open \
+  if(!g.out.pFile) FileWrapper_open(&g.out, "-", "w");    \
+  if(!inclCount){ db_include_dir_add("."); ++inclCount; } (void)0
 
   g.zArgv0 = argv[0];
 #define DOIT if(doIt)
@@ -2620,14 +2666,18 @@ int main(int argc, char const * const * argv){
       do_infile:
         DOIT {
           ++nFile;
-          if(!g.out.pFile) FileWrapper_open(&g.out, "-", "w");
-          if(!inclCount){
-            db_include_dir_add(".");
-            ++inclCount;
-          }
+          g_out_open;
           cmpp_process_file(zVal);
         }
       }
+      ISFLAG("e"){
+        ARGVAL;
+        DOIT {
+          ++nFile;
+          g_out_open;
+          cmpp_process_string("-e script", ustr_c(zVal), -1);
+        }
+      }
       ISFLAG("@"){
         NOVAL;
         DOIT {
@@ -2705,6 +2755,6 @@ int main(int argc, char const * const * argv){
     }
   }
   end:
-  g_cleanup(0);
+  g_cleanup(1);
   return rc ? EXIT_FAILURE : EXIT_SUCCESS;
 }
index c0a7a7fa25ac6585e87e3bd88037d1798e76ef28..d2e3ae02e471594e13f3e4db9062636226eb2f62 100644 (file)
@@ -1353,7 +1353,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
     })/*oo1.DB/Stmt.wrapHandle()*/
 
   ////////////////////////////////////////////////////////////////////
-    .t('sqlite3_db_config() and sqlite3_db_status()', function(sqlite3){
+    .t('sqlite3_db_config() and sqlite3_status()', function(sqlite3){
       let rc = capi.sqlite3_db_config(this.db, capi.SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, 0, 0);
       T.assert(0===rc);
       rc = capi.sqlite3_db_config(this.db, capi.SQLITE_DBCONFIG_MAX+1, 0);
index c74317dcc25022e30efddbe6dffc846a9908bf5c..e89d58835962852f92fed4b8e9acbddf4fb637b0 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\smemory\sallocation\sin\sthe\s".table"\scommand\sof\sthe\s.cli\swhen\sthe\snumber\nof\stables\sin\sthe\sdatabase\sfile\sapproaches\s2\sbillion.
-D 2025-10-15T10:52:45.276
+C Resolve\sa\svalgrind-reported\serror\sin\sext/wasm/c-pp-lite.c\scaused\sby\ssuccessful\sexit\scolliding\swith\sthe\satexit()\shandler.\sAdd\s-e\sSCRIPT\ssupport\sto\sc-pp-lite\sto\sfacilitate\stesting.
+D 2025-10-15T23:13:50.075
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -608,7 +608,7 @@ F ext/wasm/api/sqlite3-vtab-helper.c-pp.js 9097074724172e31e56ce20ccd7482259cf72
 F ext/wasm/api/sqlite3-wasm.c dd7fc1d535281f0d5d2732bb1b662d1d403a762f07b63c2ea5663053377b2804
 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bda1c75bd674a92a0e27cc2f3d46dbbf21e422413f8046814515a0bd7409328a
 F ext/wasm/api/sqlite3-worker1.c-pp.js 802d69ead8c38dc1be52c83afbfc77e757da8a91a2e159e7ed3ecda8b8dba2e7
-F ext/wasm/c-pp-lite.c 16250600fe18723e0cee4227161101ccb54f10fa6136bd208b479cf596df0f75
+F ext/wasm/c-pp-lite.c bea58ca9d07bc8f40c6348008ccbd197ae3e60f57319884fa92ac0f3659e9151
 F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51
 F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15
 F ext/wasm/common/testing.css e97549bab24126c24e0daabfe2de9bb478fb0a69fdb2ddd0a73a992c091aad6f
@@ -648,7 +648,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
 F ext/wasm/tester1-worker.c-pp.html 883881eeac14eeeecc8ff22acf9fe0f18a97cacb48be08ebb0bae891ceded584
 F ext/wasm/tester1.c-pp.html 949920126dcf477925d8d540093d9cc374d3ab4c4ddee920c1dcadcf37917306
-F ext/wasm/tester1.c-pp.js 23fc1223e75228f054148eeb8469ad114e9b2881b9f437fa291b8da06d021ce3
+F ext/wasm/tester1.c-pp.js 614cac06524ec2202027c7f6cc5e94d91482b0eb6aa969f252517047596e404e
 F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e
 F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88
 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
@@ -2171,8 +2171,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 1738f0bdf5941a70684c82d2040561e53a272595026a837a9f9bab8508a46480
-R 1dbf964e481b54df9bb3b131a4237ef8
-U drh
-Z fd056c381ae9f263080e8efcbef5c8b3
+P 5cbccab499bc3983aac1f57355552db607dee6c7ef4eb00d794dbee89c18db70
+R 44a4b71eb5503b7bbc17ff76cb6ac620
+U stephan
+Z 018b10b1849964499337242af9f8fecf
 # Remove this line to create a well-formed Fossil manifest.
index 26a904132829f48856576864d97140e7db2a54d8..edf58fb0ca286a6de5027adae5b9cf96edfc58bb 100644 (file)
@@ -1 +1 @@
-5cbccab499bc3983aac1f57355552db607dee6c7ef4eb00d794dbee89c18db70
+7801c7225a18ccb2216b01663b30e3eb90a961e3d165af73f964c515b74fe745