NetBSD Problem Report #36064

From dholland@eecs.harvard.edu  Fri Mar 23 19:44:27 2007
Return-Path: <dholland@eecs.harvard.edu>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 4DD4463B853
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 23 Mar 2007 19:44:27 +0000 (UTC)
Message-Id: <20070323194403.415CFF8FD@tanaqui.eecs.harvard.edu>
Date: Fri, 23 Mar 2007 15:44:03 -0400 (EDT)
From: dholland@eecs.harvard.edu
Reply-To: dholland@eecs.harvard.edu
To: gnats-bugs@NetBSD.org
Subject: code that *looks* wrong in citrus_iconv
X-Send-Pr-Version: 3.95

>Number:         36064
>Category:       lib
>Synopsis:       code that *looks* wrong in citrus_iconv
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 23 19:45:00 +0000 2007
>Closed-Date:    Sat Sep 05 06:45:43 +0000 2009
>Last-Modified:  Sat Sep 05 06:45:43 +0000 2009
>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,


>Release-Note:

>Audit-Trail:
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/36064 CVS commit: src/lib/libc/citrus
Date: Sat, 5 Sep 2009 06:44:27 +0000

 Module Name:	src
 Committed By:	dholland
 Date:		Sat Sep  5 06:44:27 UTC 2009

 Modified Files:
 	src/lib/libc/citrus: citrus_iconv.c

 Log Message:
 Add parentheses around a misleading string constant concatenation,
 from (my own, very old) PR 36064.


 To generate a diff of this commit:
 cvs rdiff -u -r1.7 -r1.8 src/lib/libc/citrus/citrus_iconv.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sat, 05 Sep 2009 06:45:43 +0000
State-Changed-Why:
fixed


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.