From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: replace alloca with strdup Date: Sat, 21 May 2005 19:25:10 +0200 Message-ID: <85y8a81og9.fsf@lola.goethe.zz> References: <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 1116697940 29791 80.91.229.2 (21 May 2005 17:52:20 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 21 May 2005 17:52:20 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 21 19:52:19 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DZY8W-0001mN-Gj for ged-emacs-devel@m.gmane.org; Sat, 21 May 2005 19:51:44 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DZY1Z-0004UE-Rg for ged-emacs-devel@m.gmane.org; Sat, 21 May 2005 13:44:33 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DZY16-0004Oh-C7 for emacs-devel@gnu.org; Sat, 21 May 2005 13:44:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DZY11-0004MV-FZ for emacs-devel@gnu.org; Sat, 21 May 2005 13:43:59 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DZY11-0004KE-9i for emacs-devel@gnu.org; Sat, 21 May 2005 13:43:59 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DZY6H-0008LN-GM for emacs-devel@gnu.org; Sat, 21 May 2005 13:49:25 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1DZXwi-0008QN-Tc for emacs-devel@gnu.org; Sat, 21 May 2005 13:39:33 -0400 Original-Received: by lola.goethe.zz (Postfix, from userid 1002) id DC21D1CE2C98; Sat, 21 May 2005 19:25:10 +0200 (CEST) Original-To: emacs-devel@gnu.org In-Reply-To: <20050521163028.GM28212@boetes.org> (Han Boetes's message of "Sat, 21 May 2005 18:30:06 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) 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:37439 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:37439 Han Boetes writes: > 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. Disadvantage: memory leak. I don't like it. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum