On Wed, Sep 10, 2025 at 1:16 PM NightStrike <nightstr...@gmail.com> wrote:
>
>
>
> On Mon, Sep 8, 2025, 03:47 Chris Packham via Gcc <gcc@gcc.gnu.org> wrote:
>>
>> Hi GCC,
>>
>> For various reasons I find myself working with a few code bases that define
>> their own wrappers for memset(). Unfortunately these wrappers defeat gccs
>> ability to detect when the size of the pointer is passed instead of the
>> size of the pointed to object.
>>
>> Is there any attribute I can set on the memset like functions that will let
>> gcc know to perform the same kinds of checks as the standard memset
>> function?
>>
>> Thanks,
>> Chris
>
>
> Would nonnull_if_nonzero help?

It's in the ball-park but not quite. I'm trying to catch cases where a
non-zero size is passed but it's wrong.

GCC will warn if I do something like

struct foo *pt = &some_foo;
memset(pt, 0, sizeof(pt));

test.c:13:29: warning: argument to ‘sizeof’ in ‘memset’ call is the
same expression as the destination; did you mean to dereference it?
[-Wsizeof-pointer-memaccess]

But if for some reason I have

struct foo *pt = &some_foo;
super_sdk_memset(pt, 0, sizeof(pt));

Then it doesn't know to apply the same heuristic to my vendors[*]
memset wrapper.

[*] quite why vendors insist on wrapping basic C functions with these
terrible wrappers is beyond me but I don't think I can change 30 years
of industry practice.

Reply via email to