[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#222189: marked as done (libc6-dev: strtol() argument type mismatch (endptr should be const char **))



Your message dated Fri, 08 Oct 2004 09:48:02 +0900
with message-id <81pt3uvxvh.wl@omega.webmasters.gr.jp>
and subject line Bug#222189: libc6-dev: strtol() argument type mismatch (endptr should be const char **)
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 26 Nov 2003 02:43:37 +0000
>From pvz@linux.se Tue Nov 25 20:43:37 2003
Return-path: <pvz@linux.se>
Received: from mail.g.bonet.se [212.181.52.4] 
	by master.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1AOpeS-0006NR-00; Tue, 25 Nov 2003 20:43:36 -0600
Received: from tanya (mail@as14-6-3.o.s.bonet.se [217.215.216.100])
	by mail.g.bonet.se (8.12.10/8.12.10) with ESMTP id hAQ2g9XS096021;
	Wed, 26 Nov 2003 03:42:38 +0100 (CET)
	(envelope-from pvz@linux.se)
Received: from pvz by tanya with local (Exim 3.36 #1 (Debian))
	id 1AOpdT-0005pU-00; Wed, 26 Nov 2003 03:42:35 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-15"
From: Per von Zweigbergk <pvz@e.kth.se>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: libc6-dev: strtol() argument type mismatch (endptr should be const char **)
X-Mailer: reportbug 2.36
Date: Wed, 26 Nov 2003 03:42:35 +0100
Message-Id: <E1AOpdT-0005pU-00@tanya>
Sender: Per von Zweigbergk <pvz@linux.se>
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mail.g.bonet.se id hAQ2g9XS096021
Delivered-To: submit@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 
	2.60-master.debian.org_2003_11_25-bugs.debian.org_2003_11_20 
	(1.212-2003-09-23-exp) on master.debian.org
X-Spam-Status: No, hits=-5.0 required=4.0 tests=HAS_PACKAGE autolearn=no 
	version=2.60-master.debian.org_2003_11_25-bugs.debian.org_2003_11_20
X-Spam-Level: 

Package: libc6-dev
Version: 2.3.2.ds1-10
Severity: minor

I'd like to suggest a change to one of the arguments of the functions
in the strtol() family. The change can be done without breaking either
source or binary compatibility to either glibc itself, or any other C
libraries. I will only talk about strtol() in this bug report, but my
comments apply to all other functions in the same family.

Let us examine strtols function prototype (from the manual page):

long int strtol(const char *nptr, char **endptr, int base);

The first argument, nptr, points to the start of the string to be
converted, and endptr (optionally) points to a character pointer.

After calling strtol, *endptr is set to where the conversion ended,
which by definition is inside the string pointed to by nptr.

We here see that there is a type mismatch. Because nptr is defined as
const char *, it would be reasonable to type endptr as const char **.
It doesn't matter that *endptr is modified, the const in this case
applies to the actual characters inside the string, not to the
pointer.

Effectively, this means that the person using this function to parse
const char * strings is forced to cast the second argument to avoid a
warning, that is not valid in any case!

Changing the type of the endptr argument should not cause any problems
with binary compatibility -- and the only possible problem that could
arise with source compatibility would be the addition of a warning
(which could cause the program not to compile if -Werror was passed to
gcc.)

If nothing else, I think a note about this ideosyncracy should be made
in the manual page, under either NOTES or BUGS, reassuring the
programmer that casting a const char ** to char ** as argument to endptr
is safe.

-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux tanya 2.4.20 #1 m=E5n mar 31 19:30:02 CEST 2003 i686
Locale: LANG=3Dsv_SE, LC_CTYPE=3Dsv_SE

Versions of packages libc6-dev depends on:
ii  libc6                 2.3.2.ds1-10       GNU C Library: Shared librar=
ies an
ii  linux-kernel-headers  2.5.999-test7-bk-9 Linux Kernel Headers for dev=
elopme

-- no debconf information


---------------------------------------
Received: (at 222189-done) by bugs.debian.org; 8 Oct 2004 00:48:03 +0000
>From gotom@debian.or.jp Thu Oct 07 17:48:03 2004
Return-path: <gotom@debian.or.jp>
Received: from omega.webmasters.gr.jp (webmasters.gr.jp) [218.44.239.78] 
	by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1CFivT-00083N-00; Thu, 07 Oct 2004 17:48:03 -0700
Received: from omega.webmasters.gr.jp (localhost [127.0.0.1])
	by webmasters.gr.jp (Postfix) with ESMTP
	id 57DC4DEB5E; Fri,  8 Oct 2004 09:48:02 +0900 (JST)
Date: Fri, 08 Oct 2004 09:48:02 +0900
Message-ID: <81pt3uvxvh.wl@omega.webmasters.gr.jp>
From: GOTO Masanori <gotom@debian.or.jp>
To: Per von Zweigbergk <pvz@e.kth.se>, 222189-done@bugs.debian.org
Subject: Re: Bug#222189: libc6-dev: strtol() argument type mismatch (endptr should be const char **)
In-Reply-To: <E1AOpdT-0005pU-00@tanya>
References: <E1AOpdT-0005pU-00@tanya>
User-Agent: Wanderlust/2.9.9 (Unchained Melody) SEMI/1.14.3 (Ushinoya)
 FLIM/1.14.3 (=?ISO-8859-4?Q?Unebigory=F2mae?=) APEL/10.3 Emacs/21.2
 (i386-debian-linux-gnu) MULE/5.0 (SAKAKI)
MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya")
Content-Type: text/plain; charset=US-ASCII
Delivered-To: 222189-done@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_03_25 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-6.0 required=4.0 tests=BAYES_00,HAS_BUG_NUMBER 
	autolearn=no version=2.60-bugs.debian.org_2004_03_25
X-Spam-Level: 

At Wed, 26 Nov 2003 03:42:35 +0100,
Per von Zweigbergk wrote:
> long int strtol(const char *nptr, char **endptr, int base);
> 
> The first argument, nptr, points to the start of the string to be
> converted, and endptr (optionally) points to a character pointer.
> 
> After calling strtol, *endptr is set to where the conversion ended,
> which by definition is inside the string pointed to by nptr.
> 
> We here see that there is a type mismatch. Because nptr is defined as
> const char *, it would be reasonable to type endptr as const char **.
> It doesn't matter that *endptr is modified, the const in this case
> applies to the actual characters inside the string, not to the
> pointer.

(1) SUS, POSIX, ISO C, and so on, defined char **endptr.
(2) endptr may point to NULL.  Think about why the return type of
    strpbrk() is not const.

I close it.

Regards,
-- gotom



Reply to: