Ethereal-dev: Re: [Ethereal-dev] Portable use of alloca()

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Wed, 10 Sep 2003 13:07:57 -0700

On Sep 10, 2003, at 9:19 AM, Albert Chin wrote:

Use of alloca() differs depending on platform. Stolen from Proftpd's
lib/glibc-glob.c file which is under the LGPL.

That produces some compiler whining when I compiled it:

	packet-lwapp.c:56:1: warning: "alloca" redefined
	In file included from /usr/include/stdlib.h:64,
                 from packet-lwapp.c:38:
/usr/include/alloca.h:43:1: warning: this is the location of the previous definition

The simplest way to avoid problems with "alloca()" is not to use it, and it's not necessary in this case:

Index: packet-lwapp.c
===================================================================
RCS file: /cvsroot/ethereal/packet-lwapp.c,v
retrieving revision 1.2
diff -c -r1.2 packet-lwapp.c
*** packet-lwapp.c	29 Aug 2003 22:57:55 -0000	1.2
--- packet-lwapp.c	10 Sep 2003 20:06:13 -0000
***************
*** 264,277 ****
      header.length = g_ntohs(header.length);

      if (check_col(pinfo->cinfo, COL_INFO)) {
!         gchar *description;
!
!         description = match_strval(header.type, control_msg_vals);
!         if (!description) {
!             description = alloca(120);
!             sprintf(description, "Bad Type: 0x%02x", header.type);
!         }
!         col_append_str(pinfo->cinfo, COL_INFO, description);
      }

/* In the interest of speed, if "tree" is NULL, don't do any work not
--- 264,271 ----
      header.length = g_ntohs(header.length);

      if (check_col(pinfo->cinfo, COL_INFO)) {
!         col_append_str(pinfo->cinfo, COL_INFO,
! val_to_str(header.type, control_msg_vals, "Bad Type: 0x%02x"));
      }

/* In the interest of speed, if "tree" is NULL, don't do any work not


I've checked that in.