Subject: bin/30051: iconv(1) error message is misleading
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <jklowden@schemamania.org>
List: netbsd-bugs
Date: 04/24/2005 17:47:00
>Number: 30051
>Category: bin
>Synopsis: iconv(1) error message is misleading
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Apr 24 17:47:00 +0000 2005
>Originator: jklowden@schemamania.org
>Release: NetBSD 2.0
>Organization:
>Environment:
System: NetBSD oak.schemamania.org 2.0 NetBSD 2.0 (GENERIC) #0: Wed Dec 1 10:58:25 UTC 2004 builds@build:/big/builds/ab/netbsd-2-0-RELEASE/i386/200411300000Z-obj/big/builds/ab/netbsd-2-0-RELEASE/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
$ ident `which iconv`
/usr/bin/iconv: # sorry, the binary seems not to have an ident string?
$NetBSD: crt0.c,v 1.13 2003/07/26 19:24:27 salo Exp $
>Description:
Given bad input, __iconv() returns EINVAL, which is good. But
when iconv(1) calls errx with EINVAL, the user sees:
iconv: iconv(): Invalid argument
which to my mind a reasonable user would interpret as meaning the command-line
options were wrong, not that the inputs were bad. If it called errx with
EILSEQ, you'd see "iconv: iconv(): Illegal byte sequence", which at least points
the user at the data.
>How-To-Repeat:
$ echo 'hi' | iconv -t ascii -f ucs-2le
iconv: iconv(): Invalid argument
>Fix:
Well, here's my suggestion.
Index: iconv.c
===================================================================
RCS file: /cvsroot/src/usr.bin/iconv/iconv.c,v
retrieving revision 1.6
diff -u -r1.6 iconv.c
--- iconv.c 21 Dec 2004 11:33:07 -0000 1.6
+++ iconv.c 24 Apr 2005 12:03:34 -0000
@@ -124,9 +128,9 @@
INBUFSIZE-inbytes, fp);
if (ret == 0) {
if (feof(fp))
- errx(EXIT_FAILURE,
- "iconv(): %s",
- strerror(EINVAL));
+ errx(EXIT_FAILURE,
+ "iconv(): %s",
+ strerror(EILSEQ));
else
err(EXIT_FAILURE, "fread()");
}