Fix UB in void* pointer arithmetic - #1476
StormBytePP wants to merge 1 commit into
Conversation
|
Maybe just change the original type instead of casting N times? |
I wanted to maintain the original format so the changes introduced are minimal. Edit: There are some fields which still require explicit casts if original type is changed (at least in mingw) like: So I reverted because I think it is more readable to have all casted uniformly instead of sometimes and sometimes not. What do you think? |
d3ef638 to
8384c37
Compare
Signed-off-by: David C. Manuelda <StormByte@gmail.com>
Signed-off-by: David C. Manuelda <StormByte@gmail.com>
8384c37 to
87a98dd
Compare
|
Rebased onto current The fail-path leak this PR originally fixed is already handled upstream: What remains is the pointer bump in |
Fix undefined behavior in
void*pointer arithmetic and a potential memory leak in the failure path ofvif_init().Changes
data += Noperations (which are UB onvoid*per C standard) with the portable and well-defined idiomdata = (char *)data + N.fail:label, we now free the original allocation pointer (s->public.buf.data) instead of the advanceddatapointer, preventing a memory leak whenvmaf_feature_name_dict_from_provided_features()fails.Why
void*aschar*for arithmetic), which is not guaranteed by the C standard and can break under strict conformance or aggressive optimizers.The memory layout and runtime behavior remain identical — only the correctness and portability are improved.
No functional change, only standard corrections.