Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Apr 2002 17:43:50 -0500 (EST)
From:      Mikhail Teterin <mi@aldan.algebra.com>
To:        obrien@FreeBSD.org
Cc:        cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/usr.bin/yacc main.c
Message-ID:  <200204042243.g34MhonF007316@aldan.algebra.com>
In-Reply-To: <200204042215.g34MFDb67996@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204042243.g34MhonF007316>