Skip Vptr checks when the pointer value is null.
In general static_cast on null pointers causes undefined behaviors, it may not depending on the contexts. This patch enforces to skip null pointers just like it was done in -fsanitize=null.
Differential D4412
[UBsan] Skip -fsanitize=vptr instrumentations when the pointer value is null byoungyoung on Jul 7 2014, 1:59 PM. Authored by
Details
Diff Detail Event TimelineComment Actions Please provide a test.
Comment Actions Expanded a comment, and added a testcase. I'm not sure whether the checks in the testcase would be enough, so please let me know if it doesn't.
Comment Actions Update the patch as commented except the test cast folding. Richard, could you please point which file should I fold into for the testcase? As far as I checked, all existing ubsan tests are written in C (except type-blacklist one), but this case has to be done in C++. Comment Actions rsmith@ - could you please land this patch as I don't have a commit permission?
|
Nit: lowercase 'v'.
It'd be nice to expand on this a bit: a null pointer here is undefined behavior, but if -fsanitize=null is not enabled, we don't want to change the behavior of code in that case, so that the user doesn't have to fix all their null pointer bugs before they can find their type mismatch bugs (which are likely to be more serious).