Hello list.
Compiling my program using clang-cl ver. 20.1 and UBSAN (Undefined Sanitizer, option -fsanitize=undefined) triggers
several UBSAN events at runtime. E.g. when storing into a DWORD from an address not a multiple of 4 bytes.
Like in this report:I.e. code such as:My fix was simply this macro:And use it like this:I'm not sure if such an unaligned is so bad, but though I just let you know.
Compiling my program using clang-cl ver. 20.1 and UBSAN (Undefined Sanitizer, option -fsanitize=undefined) triggers
several UBSAN events at runtime. E.g. when storing into a DWORD from an address not a multiple of 4 bytes.
Like in this report:
Code:
Everything.c:2395:15: runtime error: load of misaligned address 0x1230caaa0719 for type 'DWORD' (aka 'unsigned long'), which requires 4 byte alignment0x1230caaa0719: note: pointer points here 64 6c 6c 00 1e 00 00 00 46 3a 5c 67 76 5c 57 69 6e 4b 69 74 5c 44 65 62 75 67 67 65 72 73 5c 78 ^ #0 0x7ff6f8a9dda0 in _Everything_GetRequestData F:\gv\VC_project\EnvTool\src\Everything.c:2395 #1 0x7ff6f8aa38e5 in Everything_GetResultFullPathNameA F:\gv\VC_project\EnvTool\src\Everything.c:2045 #2 0x7ff6f8a1a082 in do_check_evry F:\gv\VC_project\EnvTool\src\envtool.c:2211 ...Code:
if (dwRequestType == EVERYTHING_REQUEST_FILE_NAME) { return p; } len = *(DWORD *) p; // << !! here p += sizeof(DWORD);Code:
#ifdef USE_UBSAN #define UNALIGNED_DWORD_STORE(dst, src) memcpy (&dst, src, sizeof(dst))#else #define UNALIGNED_DWORD_STORE(dst, src) dst = *(DWORD*)(src)#endifCode:
UNALIGNED_DWORD_STORE (len, p); p += sizeof(DWORD);Statistics: Posted by Gisle Vanem — Thu Jul 17, 2025 8:50 am








