From: drh <> Date: Fri, 26 Dec 2025 20:13:32 +0000 (+0000) Subject: Work around the Windows "Worst-Fit" bug in the "sqldiff.exe" program. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f56d23f9c7368a17035f1593674bdf639b20f60;p=thirdparty%2Fsqlite.git Work around the Windows "Worst-Fit" bug in the "sqldiff.exe" program. FossilOrigin-Name: f41851587328f8b434e66987765324b7bf5746ecdf3a9f2869000276e0f79401 --- diff --git a/Makefile.msc b/Makefile.msc index 4649caf934..f9d76d61cf 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1866,8 +1866,8 @@ $(SQLITE3EXE): shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLIT /link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) # <> -sqldiff.exe: $(TOP)\tool\sqldiff.c $(TOP)\ext\misc\sqlite3_stdio.h $(TOP)\ext\misc\sqlite3_stdio.c $(SQLITE3C) $(SQLITE3H) $(LIBRESOBJS) - $(LTLINK) $(NO_WARN) -I$(TOP)\ext\misc $(TOP)\tool\sqldiff.c $(TOP)\ext\misc\sqlite3_stdio.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) $(LIBRESOBJS) +sqldiff.exe: $(TOP)\tool\sqldiff.c $(TOP)\ext\misc\sqlite3_stdio.h $(TOP)\ext\misc\sqlite3_stdio.c $(SQLITE3C) $(SQLITE3H) $(LIBRESOBJS) $(TOP)\tool\winmain.c + $(LTLINK) $(NO_WARN) -I$(TOP)\ext\misc $(TOP)\tool\sqldiff.c $(TOP)\ext\misc\sqlite3_stdio.c $(TOP)\tool\winmain.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) $(LIBRESOBJS) dbhash.exe: $(TOP)\tool\dbhash.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) $(TOP)\tool\dbhash.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) diff --git a/manifest b/manifest index bbc866276a..4e937737d9 100644 --- a/manifest +++ b/manifest @@ -1,12 +1,12 @@ -C To\sensure\sthat\sthe\ssqlite3_hard_heap_limit()\scall\sit\smakes\sis\seffective,\sadd\s"sqlite3_config(SQLITE_CONFIG_MEMSTATUS,\s1);"\sto\sfuzzcheck.c. -D 2025-12-26T17:23:25.617 +C Work\saround\sthe\sWindows\s"Worst-Fit"\sbug\sin\sthe\s"sqldiff.exe"\sprogram. +D 2025-12-26T20:13:32.174 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md 6bc480fc673fb4acbc4094e77edb326267dd460162d7723c7f30bee2d3d9e97d F Makefile.in 3ce07126d7e87c7464301482e161fdae6a51d0a2aa06b200b8f0000ef4d6163b F Makefile.linux-generic bd3e3cacd369821a6241d4ea1967395c962dfe3057e38cb0a435cee0e8b789d0 -F Makefile.msc 39d4085a92ef891ac9290277d910965b44d31e385beceaabc37aa5e6e7b71ecb +F Makefile.msc fcf72b1401e1b2b1cb6f9b84ee961f6dff5bc808c249d76353a4a5447dbaf0b9 F README.md 3fa51fc7ababc32edd175ae8b2986c86d5ea120c1cb1e57c7f7849492d1405ec F VERSION 74672bfd4c7826c0fc6f84762488a707c52e7d2d94af42ccb0edcc6c74311c41 F art/icon-243x273.gif 9750b734f82fdb3dc43127753d5e6fbf3b62c9f4e136c2fbf573b2f57ea87af5 @@ -2167,7 +2167,7 @@ F tool/soak1.tcl a3892082ed1079671565c044e93b55c3c7f38829aedf53cc597c65d23ffdadd F tool/spaceanal.tcl 1f83962090a6b60e1d7bf92495d643e622bef9fe82ea3f2d22350dcbce9a12d0 F tool/spellsift.tcl 52b4b04dc4333c7ab024f09d9d66ed6b6f7c6eb00b38497a09f338fa55d40618 x F tool/split-sqlite3c.tcl 4969fd642dad0ea483e4e104163021d92baf98f6a8eac981fe48525f9b873430 -F tool/sqldiff.c 134be7866be19f8beb32043d5aea5657f01aaeae2df8d33d758ff722c78666b9 +F tool/sqldiff.c 68f88017de3bed3aa65c93a4cf3a04d0989d158bc6fad8f1475beeeea1aae3ac F tool/sqlite3_analyzer.c.in 14f02cb5ec3c264cd6107d1f1dad77092b1cf440fc196c30b69ae87b56a1a43b F tool/sqlite3_rsync.c d0e58a1e49fe2192c3ee0b697aed182d502bebfe5b4b406ba6b2baa52a04ecbe F tool/sqltclsh.c.in c103c6fc7d42bce611f9d4596774d60b7ef3d0b291a1f58c9e6184e458b89296 @@ -2187,8 +2187,9 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8ab37d9fb909dc6bfbede004f342e6c1625c99df9b316807dc77a9a636ee6873 -R 81328fa787ead27d2d0283ffbcc32c4e -U dan -Z 0315561ae7dfa48747bda2c07292a1fd +F tool/winmain.c f40bccf0236f8bcc34b299781b7d34cb269ace23afe5c1b8a9d966e2fa1ce9e5 +P f7736af849d910f04d8622ed7c6e705d84cf22f0a73dca0f30eead9bd1f28bc7 +R 43855622a7f99eaf2e84b3fd5150fbc0 +U drh +Z 568ba1e2be02bc872c4ea7b34bd66c20 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 12f52aad97..927bc878a4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f7736af849d910f04d8622ed7c6e705d84cf22f0a73dca0f30eead9bd1f28bc7 +f41851587328f8b434e66987765324b7bf5746ecdf3a9f2869000276e0f79401 diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 44bf488f86..b1eec92fdb 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -1896,6 +1896,11 @@ static void showHelp(void){ ); } +/* work-around the Microsoft "WorstFit" bug */ +#ifdef _WIN32 +#define main utf8_main +#endif + int main(int argc, char **argv){ const char *zDb1 = 0; const char *zDb2 = 0; diff --git a/tool/winmain.c b/tool/winmain.c new file mode 100644 index 0000000000..a874cf8637 --- /dev/null +++ b/tool/winmain.c @@ -0,0 +1,78 @@ +/* +** 2025-12-26 +** +** 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 a substitute process entry point for windows +** that correctly interprets command-line arguments as UTF-8. This is +** a work-around for the (unfixed) Windows bug known as "WorstFit" and +** described at: +** +** * https://news.ycombinator.com/item?id=42647101 +** +** USAGE: +** +** If you have a command-line program coded to C-language standard in which +** the entry point is: +** +** int main(int argc, char **argv){...} +** +** That does not work on Windows if there are non-ASCII characters on the +** command line. Programs are expected to use an alternative entry point: +** +** int wmain(int wargc, wchar_t **wargv){...} +** +** This file implements _wmain() but then converts all of the wargv elements +** to UTF-8 and passes them off to utf8_main(). +** +** So, a command-line tool that implements the standard entry point can be +** modified by adding the following lines just prior to main(): +** +** #ifdef _WIN32 +** #define main utf8_main +** #endif +** +** Then, include this file in the list of files that implement the program, +** and the program will work correctly, even on Windows. +*/ +#include +#include + +extern int utf8_main(int,char**); +int wmain(int argc, wchar_t **wargv){ + int rc, i; + char **argv = malloc( sizeof(char*) * (argc+1) ); + char **orig = argv; + if( argv==0 ){ + fprintf(stderr, "malloc failed\n"); + exit(1); + } + for(i=0; i