Subject: lib/36064: code that *looks* wrong in citrus_iconv
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <dholland@eecs.harvard.edu>
List: netbsd-bugs
Date: 03/23/2007 19:45:00
>Number:         36064
>Category:       lib
>Synopsis:       code that *looks* wrong in citrus_iconv
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 23 19:45:00 +0000 2007
>Originator:     David A. Holland <dholland@eecs.harvard.edu>
>Release:        NetBSD 4.99.9 (20070221; -r1.6 of citrus_iconv.c)
>Organization:
>Environment:
System: NetBSD tanaqui 4.99.9 NetBSD 4.99.9 (TANAQUI) #8: Tue Jan 30 17:29:55 EST 2007 dholland@tanaqui:/usr/src/sys/arch/i386/compile/TANAQUI i386
Architecture: i386
Machine: i386
>Description:

While looking for an unrelated problem I came across the following
line of code:

    snprintf(path, (size_t)PATH_MAX, "%s/" _CITRUS_ICONV_DIR, curdir);

While it's perfectly correct, it *looks* wrong because of several
circumstances: (1) the absence of a comma is not obvious at a glance,
especially with the adjoining underscore; (2) the idiom

    snprintf(path, sizeof(path), "%s/%s", something_dir, something_file);

is very common; and (3) while _CITRUS_ICONV_DIR is not actually the
name of a directory, it looks like it is.

It fooled me, even though I knew what _CITRUS_ICONV_DIR was because of
what I'd just been chasing, and I nearly "fixed" it. To prevent
someone else from making the same mistake I suggest the patch below --
-- or converting it to the idiomatic form.

>How-To-Repeat:
n/a
>Fix:
Index: citrus_iconv.c
===================================================================
RCS file: /cvsroot/src/lib/libc/citrus/citrus_iconv.c,v
retrieving revision 1.6
diff -u -r1.6 citrus_iconv.c
--- citrus_iconv.c	30 Dec 2004 05:03:48 -0000	1.6
+++ citrus_iconv.c	23 Mar 2007 19:28:41 -0000
@@ -107,7 +107,7 @@
 	char *p, path[PATH_MAX];
 
 	/* iconv.dir path */
-	snprintf(path, (size_t)PATH_MAX, "%s/" _CITRUS_ICONV_DIR, curdir);
+	snprintf(path, (size_t)PATH_MAX, ("%s/" _CITRUS_ICONV_DIR), curdir);
 
 	/* lookup db */
 	cp = p = _lookup_simple(path, key, linebuf, linebufsize,