https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114113

            Bug ID: 114113
           Summary: bogus -Walloc-zero warning
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: f.heckenb...@fh-soft.de
  Target Milestone: ---

% cat test.c
void *malloc (long unsigned int size);

int p[2] = { 1, 0 };
int *a;

int main ()
{
  int n = 0;
  while (p[n])
    n++;
  a = (int *) malloc (n * sizeof (int));
  int i;
  for (i = 0; i < n; i++)
    a[i] = 0;
}
% gcc -O -Walloc-zero test.c
test.c: In function 'main':
test.c:11:15: warning: argument 1 value is zero [-Walloc-zero]
   11 |   a = (int *) malloc (n * sizeof (int));
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~
test.c:1:7: note: in a call to allocation function 'malloc' declared here
    1 | void *malloc (long unsigned int size);
      |       ^~~~~~

Reply via email to