From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Han Boetes Newsgroups: gmane.emacs.devel Subject: replace alloca with strdup Date: Sat, 21 May 2005 18:30:06 +0200 Message-ID: <20050521163028.GM28212@boetes.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1116693536 19412 80.91.229.2 (21 May 2005 16:38:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 21 May 2005 16:38:56 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 21 18:38:53 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DZWz4-0004Kb-O5 for ged-emacs-devel@m.gmane.org; Sat, 21 May 2005 18:37:55 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DZX29-0000QE-PS for ged-emacs-devel@m.gmane.org; Sat, 21 May 2005 12:41:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DZX13-0008SV-Uh for emacs-devel@gnu.org; Sat, 21 May 2005 12:39:58 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DZX11-0008Qf-GS for emacs-devel@gnu.org; Sat, 21 May 2005 12:39:55 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DZX10-0008Mn-Ch for emacs-devel@gnu.org; Sat, 21 May 2005 12:39:54 -0400 Original-Received: from [82.73.147.65] (helo=boetes.org) by monty-python.gnu.org with smtp (Exim 4.34) id 1DZX0I-0007rx-Gn for emacs-devel@gnu.org; Sat, 21 May 2005 12:39:10 -0400 Original-Received: (qmail 693 invoked by uid 1000); 21 May 2005 16:30:29 -0000 Original-To: emacs-devel@gnu.org Mail-Followup-To: emacs-devel@gnu.org Content-Disposition: inline User-Agent: Mutt/1.5.8i X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:37436 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:37436 Hi, While looking at some compilerwarnings I found an alloca and an strcpy. And I realized this can also be done as follows: Index: xterm.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/xterm.c,v retrieving revision 1.864 diff -u -p -r1.864 xterm.c --- xterm.c 10 May 2005 09:19:19 -0000 1.864 +++ xterm.c 21 May 2005 16:23:31 -0000 @@ -7635,8 +7635,9 @@ x_connection_closed (dpy, error_message) Lisp_Object frame, tail; int count; - error_msg = (char *) alloca (strlen (error_message) + 1); - strcpy (error_msg, error_message); + if ((error_msg = strdup(error_message)) == NULL) + errx(1, "Out of memory."); + handling_signal = 0; /* Prevent being called recursively because of an error condition Advantages are: - simpler code - strdup is more portable - error handling - you don't have to worry about strdup concerning security I hope you like the idea. # Han