[cfe-commits] Patch: Warn on zero-length memaccess

Chris Pickel sfiera at sfzmail.com
Sun Jun 17 13:53:08 PDT 2012


On Thu, Jun 14, 2012 at 12:21 AM, Chandler Carruth <chandlerc at google.com> wrote:
> On Wed, Jun 13, 2012 at 10:21 AM, Chris Pickel <sfiera at sfzmail.com> wrote:
>> After spending far too long tracking down a bug which was ultimately
>> caused by the line:
>>
>>  memset(&x, sizeof(x), 0);  // Should be memset(&x, 0, sizeof(x))
>
> FWIW, I think this makes more sense w/ memset than any others -- 0 isn't
> valid for either the source or destination of memcpy / memcmp / memmove.

OK, I've restricted the checks to memset(). This gets rid of the
unexpected warnings, so there are no changes necessary to any of the
existing tests.

> Also, I would want to make sure that the '0' is not actually computed from a
> macro or template parameter.

I added tests, but they fail. I'm not sure how to fix them. I disabled
the warning when IntLenExpr->is{Type,Value}Dependent(); my
understanding was that the size was value-dependent in the templated
case. Do you have an example of a similar warning that's disabled in
the same circumstances?

Also, void* doesn't disable the warning any more. I assume, if the
template and macro cases are resolved, this isn't a problem as the
recommended fix can be to remove the memset call.

Current patchset attached, but I'll edit it down once everything's resolved.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Warn-on-zero-length-memaccess.patch
Type: application/octet-stream
Size: 8200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120617/ff221776/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Restrict-0-checking-to-memset.patch
Type: application/octet-stream
Size: 11491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120617/ff221776/attachment-0001.obj>


More information about the cfe-commits mailing list