the following file
================================= foo.c ============================
#include <alloca.h>
#include <string.h>
#include <stdlib.h>

extern void bar (char*, char*);

void foo (const char *name, const char *type)
{
  {
    size_t name_len = strlen (name);
    char *name_temp = (char *) alloca (name_len);
    if (name_len > 0)
      memcpy (name_temp, name, name_len);
    {
      char name_copy[name_len + 2];
      memcpy (name_copy, name_temp, name_len);
      name_copy[name_len] = '$';
      name_copy[name_len + 1] = '\0';
      {
        size_t type_len = strlen (type);
        char *type_temp = (char *) alloca (type_len);
        if (type_len > 0)
          memcpy (type_temp, type, type_len);
        {
          char type_copy[type_len + 2];
          memcpy (type_copy, type_temp, type_len);
          type_copy[type_len] = '$';
          type_copy[type_len + 1] = '\0';
          {
            bar (name_copy, type_copy);
          }
        }
      }
    }
  }
}
================================= foo.c ============================
produces this warning:
$ gcc -c foo.c
foo.c: In function `foo':
foo.c:21: warning: alloca()ed storage released along with dynamically-sized auto
  objects
on this system: "gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)"

-- 
           Summary: strange warning about alloca
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sds at gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19881

Reply via email to