Skip to content

New option -Walloc-size causes injustified warning. #155633

@earnol

Description

@earnol

The newly added warning via #150028 is causes warning in unexpected situation.
Please see the following godbolt example.

In this example in line 12 the warning is generated, however the C99 standard clearly says:
" If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object."
And clang implementation is to return NULL pointer in such case.
Thus the warning should be consistent with clang implementation currently existing and not generate warning when realloc() is used in lieu of free().

I propose to remove the warning in case of realloc() function is receiving a zero as a second parameter.

I agree on the fact of use realloc(p, NULL) instead of free(p) is being a terrible practice, but the existing warning is confusing to to the users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions