From owner-cvs-all Thu Apr 4 14:44:37 2002 Delivered-To: cvs-all@freebsd.org Received: from aldan.algebra.com (aldan.algebra.com [216.254.65.224]) by hub.freebsd.org (Postfix) with ESMTP id 2BE2A37B419; Thu, 4 Apr 2002 14:44:30 -0800 (PST) Received: from aldan.algebra.com (localhost [127.0.0.1]) by aldan.algebra.com (8.12.2/8.12.2) with ESMTP id g34MhonF007316; Thu, 4 Apr 2002 17:43:54 -0500 (EST) (envelope-from mi@aldan.algebra.com) Message-Id: <200204042243.g34MhonF007316@aldan.algebra.com> Date: Thu, 4 Apr 2002 17:43:50 -0500 (EST) From: Mikhail Teterin Subject: Re: cvs commit: src/usr.bin/yacc main.c To: obrien@FreeBSD.org Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org In-Reply-To: <200204042215.g34MFDb67996@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/plain; charset=US-ASCII Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 4 Apr, David E. O'Brien wrote: > obrien 2002/04/04 14:15:13 PST > > Modified files: > usr.bin/yacc main.c > Log: [...] > Use strlen() rather than magic number. [...] Beware of strlen :) The magic number was just a ``sizeof temp_form'' -- computed at the code-writing time. Your change moved the computation to run-time, which, IMHO, is too far. How about the following patch, which will move it to the compile-time (untested): Index: main.c =================================================================== RCS file: /home/ncvs/src/usr.bin/yacc/main.c,v retrieving revision 1.19 diff -U2 -r1.19 main.c --- main.c 4 Apr 2002 22:15:56 -0000 1.19 +++ main.c 4 Apr 2002 22:41:35 -0000 @@ -302,9 +302,11 @@ const char *tmpdir; - if (!(tmpdir = getenv("TMPDIR"))) + if (!(tmpdir = getenv("TMPDIR"))) { tmpdir = _PATH_TMP; + len = sizeof _PATH_TMP - 1; + } else + len = strlen(tmpdir); - len = strlen(tmpdir); - i = len + strlen(temp_form) + 1; + i = len + sizeof temp_form; if (len && tmpdir[len-1] != '/') ++i; Respectfully, -mi (with too much time) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message