Overview
Artifact ID: | 9459d6bdbfb72469a74fd4db8aa1f5258c006782 |
---|---|
Ticket: | 3caef588e3cc1724a8a8426e5964a0088d35b15b
dereferencing type-punned pointer in sqlite3.c |
User & Date: | rwilson 2010-01-01 17:00:57 |
Changes
- comment changed to:
i know this is an sqlite issue, but i can't create tickets on sqlite.org, neither is the amaglamation in the sqlite source tree. when i build fossil i get the following warning: <pre> gcc -Os -Wall -DFOSSIL_I18N=0 -L/mingw/lib -I/mingw/include -I. -I./src -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -c ./src/sqlite3.c -o sqlite3.o ./src/sqlite3.c: In function `getLastErrorMsg': ./src/sqlite3.c:28450: warning: dereferencing type-punned pointer will break strict-aliasing rules </pre> the warning is innocuous, but this patch resolves it. i'm pretty sure the code is correct, but i could use a code review. hopefully, i didn't make a noob mistake. <pre> --- sqlite3.c +++ sqlite3.c @@ -28438,25 +28438,29 @@ ** buffer, excluding the terminating null char. */ DWORD error = GetLastError(); DWORD dwLen = 0; char *zOut = 0; + union { + WCHAR** pzwc; + LPWSTR lpws; + } wu; </pre> <pre> if( isNT() ){ - WCHAR *zTempWide = NULL; + *wu.pzwc = NULL; dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, - (LPWSTR) &zTempWide, + wu.lpws, 0, 0); if( dwLen > 0 ){ /* allocate a buffer and convert to UTF8 */ - zOut = unicodeToUtf8(zTempWide); + zOut = unicodeToUtf8(*wu.pzwc); /* free the system buffer allocated by FormatMessage */ - LocalFree(zTempWide); + LocalFree(*wu.pzwc); } /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. ** Since the ASCII version of these Windows API do not exist for WINCE, ** it's important to not reference them for WINCE builds. */ </pre>
- foundin changed to: "dddc514053"
- private_contact changed to: "2359089ef753bc96e12743e299243d5232c749fa"
- severity changed to: "Cosmetic"
- status changed to: "Open"
- title changed to: "dereferencing type-punned pointer in sqlite3.c"
- type changed to: "Build_Problem"