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: Select all
Everything.c:2395:15: runtime error: load of misaligned address 0x1230caaa0719 for type 'DWORD' (aka 'unsigned long'), which requires
4 byte alignment
0x1230caaa0719: 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: Select all
if (dwRequestType == EVERYTHING_REQUEST_FILE_NAME)
{
return p;
}
len = *(DWORD *) p; // << !! here
p += sizeof(DWORD);
Code: Select all
#ifdef USE_UBSAN
#define UNALIGNED_DWORD_STORE(dst, src) memcpy (&dst, src, sizeof(dst))
#else
#define UNALIGNED_DWORD_STORE(dst, src) dst = *(DWORD*)(src)
#endif
Code: Select all
UNALIGNED_DWORD_STORE (len, p);
p += sizeof(DWORD);