| Ticket UUID: | 3caef588e3cc1724a8a8426e5964a0088d35b15b | ||
| Title: | dereferencing type-punned pointer in sqlite3.c | ||
| Status: | Closed | Type: | Build_Problem |
| Severity: | Cosmetic | Priority: | |
| Subsystem: | Resolution: | External_Bug | |
| Last Modified: | 2011-09-08 19:18:24 | ||
| Version Found In: | dddc514053 | ||
| Description & Comments: | |||
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:
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 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.
--- 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;
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.
*/
dmitry added on 2011-09-08 19:18:24 UTC: | |||