This is an archive of the discontinued LLVM Phabricator instance.

Don't pass nullptr into memcpy
ClosedPublic

Authored by vitalybuka on Nov 14 2016, 2:10 PM.

Details

Summary

It's undefined according UBSAN.
Not sure which CL caused test failures, but seems writeBytes for empty buffer
should be OK.

Diff Detail

Repository
rL LLVM

Event Timeline

vitalybuka updated this revision to Diff 77886.Nov 14 2016, 2:10 PM
vitalybuka retitled this revision from to Don't pass nullptr into memcpy.
vitalybuka updated this object.
vitalybuka added reviewers: rnk, zturner.
vitalybuka added a subscriber: llvm-commits.
vitalybuka updated this revision to Diff 77887.Nov 14 2016, 2:12 PM

return early

This revision was automatically updated to reflect the committed changes.

Did this get an LGTM? This change doesn't look right. The old code would return msf_error_code::insufficient_buffer if Data.size() was greater than zero.

Not yet, it's for post-submitted review to fix UBSAN bots.
Looking.

Majnemer, You are right
// here if Buffer is empty:
if (Offset > - Data.size())

return make_error<MSFError>(msf_error_code::insufficient_buffer);

so it's essentially if (Offset >0 || Data.size() >0 )

I should submit the first patch which I've changed in the last moment for "early return" :-)

Ah, right, but I guess it's unintended one.
Then I am not sure if we want to change something here.