Debian Bug report logs - #487254
manpages-dev: *scanf may set errno to ERANGE

version graph

Package: manpages-dev; Maintainer for manpages-dev is Martin Schulze <joey@debian.org>; Source for manpages-dev is src:manpages.

Reported by: Stephane Chazelas <stephane_chazelas@yahoo.fr>

Date: Fri, 20 Jun 2008 15:42:05 UTC

Severity: normal

Found in version manpages/2.80-1

Fixed in version manpages/3.01-1

Done: Joey Schulze <joey@infodrom.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <stephane_chazelas@yahoo.fr>:
New Bug report received and forwarded. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <stephane_chazelas@yahoo.fr>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: manpages-dev: *scanf may set errno to ERANGE
Date: Fri, 20 Jun 2008 16:35:27 +0100
Package: manpages-dev
Version: 2.80-1
Severity: normal


In the GNU and UC versions of the libc (at least), the
scanf/fscanf/sscanf... functions seem to be calling strtoxxx
internally for number conversions.

In doing so, errno may be set to ERANGE when the input doesn't
fit in the number size requested and possibly to EINVAL for a
figures not in the requested base.

I think this should be mentionned. It should probably be
mentionned that one shouldn't rely on that to check whether an
out-of-range number was provided given that it is not clearly
specified by POSIX.


Also, the %as GNU extension seems not to be documented
(it may return ENOMEM) in the man page. It is in the glibc
documentation.

It doesn't seem to be supported by ucLibc but is required on LSB
3.2 conformant systems, it would seem
(http://refspecs.linux-foundation.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/baselib-scanf.html)

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.25-rc8 (PREEMPT)
Locale: LANG=en_GB.ISO-8859-15, LC_CTYPE=en_US.ISO-8859-15 (charmap=ISO-8859-15)
Shell: /bin/sh linked to /bin/bash

Versions of packages manpages-dev depends on:
ii  manpages                      2.80-1     Manual pages about using a GNU/Lin

manpages-dev recommends no packages.

-- debconf-show failed




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #10 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: 487254@bugs.debian.org
Subject: Re: manpages-dev: *scanf may set errno to ERANGE
Date: Fri, 20 Jun 2008 16:58:38 +0100
On Fri, Jun 20, 2008 at 04:35:27PM +0100, Stephane Chazelas wrote:
[...]
> In the GNU and UC versions of the libc (at least), the
> scanf/fscanf/sscanf... functions seem to be calling strtoxxx
> internally for number conversions.
> 
> In doing so, errno may be set to ERANGE when the input doesn't
> fit in the number size requested and possibly to EINVAL for a
> figures not in the requested base.
[...]

For information, dietlibc's scanf doesn't exhibit that behavior.
On other Unices, it seems to vary, and it doesn't seem to be
often clearly documented.

Best regards,
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #15 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>, 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Sun, 22 Jun 2008 08:25:56 +0200
On Fri, Jun 20, 2008 at 5:58 PM, Stephane Chazelas
<Stephane_Chazelas@yahoo.fr> wrote:
> On Fri, Jun 20, 2008 at 04:35:27PM +0100, Stephane Chazelas wrote:
> [...]
>> In the GNU and UC versions of the libc (at least), the
>> scanf/fscanf/sscanf... functions seem to be calling strtoxxx
>> internally for number conversions.
>>
>> In doing so, errno may be set to ERANGE when the input doesn't
>> fit in the number size requested and possibly to EINVAL for a
>> figures not in the requested base.
> [...]
>
> For information, dietlibc's scanf doesn't exhibit that behavior.
> On other Unices, it seems to vary, and it doesn't seem to be
> often clearly documented.

Hi Stephane,

Thanks for the note.  I will look at this a bit more.  I see you sent
a note into the Austin list about this.  Two things: it's alway worth
CCing me on such notes, since I do follow Austin.  second: you may
make more headway by raising a proper bugreport against the standard
-- these bug reports are called Aardvarks.  Look on the Austin site
for info.

Cheers,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #20 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 09:51:34 +0100
On Mon, Jun 23, 2008 at 10:34:14AM +0200, Michael Kerrisk wrote:
[...]
> Okay -- I verified this.
> 
> One of the problems here of course is that the scanf.3 page currently
> doesn't document *any* errors...
> 
> > and possibly to EINVAL for a
> > figures not in the requested base.
> 
> Can you provide an example where this error is produced?  I could not see it.

Hi Michael,

I didn't try that, that's why I said "possibly". But the
strtol man page says that it may return EINVAL so it could be
the case for sscanf as well.

[...]
> > Also, the %as GNU extension seems not to be documented
> > (it may return ENOMEM) in the man page. It is in the glibc
> > documentation.
> 
> So, this is a completely unrelated issue (other than the fact that it
> involves scanf()).  Makes it difficult to close the bug and until the
> two unrelated halves are both fixed.  Please don't do that ;-).
[...]

You're right, sorry about that. Actually I found that other one
while writing the bug report. I was looking for other errnos
that sscanf may return (here ENOMEM).

But I'm not sure if that's a bug or not as I don't know whether
manpages-dev is meant to document the GNU or other version of
the libc functions. AFAICT, the %as is a GNU extension that is
not supported anywhere else, but is required by the LSB. I don't
know what's your policy on that.

I can create a separate bug report if you want.

BTW, Michael, I take it you're the maintainer of the
manpages-dev debian package, but are you as well the maintainer
of the upstreams package, or glibc documentation?

What's the debian view on the LSB. I discovered it recently. It
seems more like an industry initiative to me at first sight
rather than  a free software initiative and it seems to be
somewhat RedHat centered so am not sure what kind of credibility
it can be given.

Cheers,
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #25 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <stephane_chazelas@yahoo.fr>, 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 10:34:14 +0200
Hi Stephane,

There are at least two logically separate bug reports here.  In such
cases, *please* file separate reports.  See below for why.

On Fri, Jun 20, 2008 at 5:35 PM, Stephane Chazelas
<stephane_chazelas@yahoo.fr> wrote:
> Package: manpages-dev
> Version: 2.80-1
> Severity: normal
>
>
> In the GNU and UC versions of the libc (at least), the
> scanf/fscanf/sscanf... functions seem to be calling strtoxxx
> internally for number conversions.
>
> In doing so, errno may be set to ERANGE when the input doesn't
> fit in the number size requested

Okay -- I verified this.

One of the problems here of course is that the scanf.3 page currently
doesn't document *any* errors...

> and possibly to EINVAL for a
> figures not in the requested base.

Can you provide an example where this error is produced?  I could not see it.

> I think this should be mentionned. It should probably be
> mentionned that one shouldn't rely on that to check whether an
> out-of-range number was provided given that it is not clearly
> specified by POSIX.

Yes, thanks for pointing that out.

> Also, the %as GNU extension seems not to be documented
> (it may return ENOMEM) in the man page. It is in the glibc
> documentation.

So, this is a completely unrelated issue (other than the fact that it
involves scanf()).  Makes it difficult to close the bug and until the
two unrelated halves are both fixed.  Please don't do that ;-).

Cheers,

Michael




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #30 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <stephane_chazelas@yahoo.fr>, 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 10:39:39 +0200
>> In the GNU and UC versions of the libc (at least), the
>> scanf/fscanf/sscanf... functions seem to be calling strtoxxx
>> internally for number conversions.
>>
>> In doing so, errno may be set to ERANGE when the input doesn't
>> fit in the number size requested
>
> Okay -- I verified this.
>
> One of the problems here of course is that the scanf.3 page currently
> doesn't document *any* errors...

Okay -- I added an ERRORS section, which documents ERANGE, among
others.  I also noted that this error is not in POSIX.




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #35 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>
Cc: 487254@bugs.debian.org, "Martin (Joey) Schulze" <joey@infodrom.org>, "Wichmann, Mats D" <mats.d.wichmann@intel.com>
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 11:08:45 +0200
Hi Stephane,

On Mon, Jun 23, 2008 at 10:51 AM, Stephane Chazelas
<Stephane_Chazelas@yahoo.fr> wrote:
> On Mon, Jun 23, 2008 at 10:34:14AM +0200, Michael Kerrisk wrote:
> [...]
>> Okay -- I verified this.
>>
>> One of the problems here of course is that the scanf.3 page currently
>> doesn't document *any* errors...
>>
>> > and possibly to EINVAL for a
>> > figures not in the requested base.
>>
>> Can you provide an example where this error is produced?  I could not see it.
>
> Hi Michael,
>
> I didn't try that, that's why I said "possibly". But the
> strtol man page says that it may return EINVAL so it could be
> the case for sscanf as well.

Okay.  Looks like it's not the case.

> [...]
>> > Also, the %as GNU extension seems not to be documented
>> > (it may return ENOMEM) in the man page. It is in the glibc
>> > documentation.
>>
>> So, this is a completely unrelated issue (other than the fact that it
>> involves scanf()).  Makes it difficult to close the bug and until the
>> two unrelated halves are both fixed.  Please don't do that ;-).
> [...]
>
> You're right, sorry about that. Actually I found that other one
> while writing the bug report. I was looking for other errnos
> that sscanf may return (here ENOMEM).

Yes, I included ENOMEM in the new ERRORS list.

> But I'm not sure if that's a bug or not as I don't know whether
> manpages-dev is meant to document the GNU or other version of
> the libc functions.

I don't know that manpages-dev has a policy on that.  Upstream
man-pages policy is: yes, document glibc specifics (but give context
re portability).

> AFAICT, the %as is a GNU extension that is
> not supported anywhere else, but is required by the LSB. I don't
> know what's your policy on that.

As above.

> I can create a separate bug report if you want.

No, I'll fix the other part this time.  Later today with a bit of
luck.  But please remember, next time(s).

> BTW, Michael, I take it you're the maintainer of the
> manpages-dev debian package,

Sometimes one could get that impression ;-).  But, no, I'm not.  I'm
merely the upstream maintainer.  (Debain derives the downstream
manpages and manpages-dev packages from my upstream man-pages.  The
Debian maintainer is Joey.)

Debian makes it easy to track their downstream man-pages bug reports,
so I do that.  It's useful for me to get bug reports that way, because
Debian users are quite active in reporting documentation bugs.  It's
useful for Debian, because I shorten the average response time on
documentation bug reports considerably (and mostly save Joey the job
of pushing fixes upstream).

> but are you as well the maintainer
> of the upstreams package, or glibc documentation?

Just upstream man-pages, which does document glibc in Section 3.

I have nothing to do with info docs though -- that's the glibc folk.

> What's the debian view on the LSB.

I don't know.

> I discovered it recently. It
> seems more like an industry initiative to me at first sight
> rather than  a free software initiative and it seems to be
> somewhat RedHat centered so am not sure what kind of credibility
> it can be given.

I don't think you could call it RH centric.  Thre are many parties
involved.  Perhaps RH is more active than many.  Mats might have
something  to say about this.

Cheers,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #40 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <stephane_chazelas@yahoo.fr>, 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 11:27:39 +0200
Stephane,

> Also, the %as GNU extension seems not to be documented
> (it may return ENOMEM) in the man page. It is in the glibc
> documentation.

Have you tried using this?  I'm trying to test now, but gcc complains
that '%a' expects type 'float *'.

Cheers,

Michael
-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #45 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 10:33:05 +0100
On Mon, Jun 23, 2008 at 11:27:39AM +0200, Michael Kerrisk wrote:
[...]
> > Also, the %as GNU extension seems not to be documented
> > (it may return ENOMEM) in the man page. It is in the glibc
> > documentation.
> 
> Have you tried using this?  I'm trying to test now, but gcc complains
> that '%a' expects type 'float *'.
[...]

~$ cat a.c
#include <stdio.h>

int main(int argc, char **argv)
{
  char *a;
  sscanf(argv[1], "%as", &a);
  puts(a);
  return 0;
}
~$ cc -Wall -c a.c
~$ ./a "xx yy"
xx
~$ gcc-2.95 -Wall -c a.c
~$ gcc-3.3 -Wall -c a.c
~$ gcc-3.4 -Wall -c a.c
~$ gcc-4.1 -Wall -c a.c
~$ gcc-4.2 -Wall -c a.c
~$ gcc-4.3 -Wall -c a.c
~$ 

Seems OK.

Maybe you had "%a" instead of "%as"?

-- 
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #50 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 10:28:50 +0100
On Mon, Jun 23, 2008 at 11:08:45AM +0200, Michael Kerrisk wrote:
[...]
> I don't know that manpages-dev has a policy on that.  Upstream
> man-pages policy is: yes, document glibc specifics (but give context
> re portability).
[...]

Thanks a lot Michael for all the details.

BTW, I just came accross:
http://www.linuxmanpages.com/man3/sscanf.3.php

Which documents the "a" flag (and the "a" conversion in the
wrong section). I'm surprised because that page claims not to
have been modified since 1995 and as far as I can remember the
glibc was not in common use on Linux at that time.

Do you have an idea where that man page comes from? Some early
glibc documentation?

See also:
http://www.rt.com/man/scanf.3.html
http://www.linuxvalley.it/encyclopedia/ldp/manpage/man3/scanf.3.php
http://www.squarebox.co.uk/cgi-squarebox/manServer/scanf.3

It seems that version of the man page is in some Linux
distribution and doesn't come from kernel.org.

Okay, after checking, it seems to be found on RedHat, at least
RHEL3.

-- 
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #55 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 11:34:30 +0200
On Mon, Jun 23, 2008 at 11:33 AM, Stephane Chazelas
<Stephane_Chazelas@yahoo.fr> wrote:
> On Mon, Jun 23, 2008 at 11:27:39AM +0200, Michael Kerrisk wrote:
> [...]
>> > Also, the %as GNU extension seems not to be documented
>> > (it may return ENOMEM) in the man page. It is in the glibc
>> > documentation.
>>
>> Have you tried using this?  I'm trying to test now, but gcc complains
>> that '%a' expects type 'float *'.
> [...]
>
> ~$ cat a.c
> #include <stdio.h>
>
> int main(int argc, char **argv)
> {
>  char *a;
>  sscanf(argv[1], "%as", &a);
>  puts(a);
>  return 0;
> }
> ~$ cc -Wall -c a.c
> ~$ ./a "xx yy"
> xx
> ~$ gcc-2.95 -Wall -c a.c
> ~$ gcc-3.3 -Wall -c a.c
> ~$ gcc-3.4 -Wall -c a.c
> ~$ gcc-4.1 -Wall -c a.c
> ~$ gcc-4.2 -Wall -c a.c
> ~$ gcc-4.3 -Wall -c a.c
> ~$
>
> Seems OK.
>
> Maybe you had "%a" instead of "%as"?

No, my problem was that my cc alias includes ansi c 99, which disables
this scanf() feature...

Thanks

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #60 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 11:40:11 +0200
On Mon, Jun 23, 2008 at 11:34 AM, Michael Kerrisk
<mtk.manpages@googlemail.com> wrote:
> On Mon, Jun 23, 2008 at 11:33 AM, Stephane Chazelas
> <Stephane_Chazelas@yahoo.fr> wrote:
>> On Mon, Jun 23, 2008 at 11:27:39AM +0200, Michael Kerrisk wrote:
>> [...]
>>> > Also, the %as GNU extension seems not to be documented
>>> > (it may return ENOMEM) in the man page. It is in the glibc
>>> > documentation.
>>>
>>> Have you tried using this?  I'm trying to test now, but gcc complains
>>> that '%a' expects type 'float *'.
>> [...]
>>
>> ~$ cat a.c
>> #include <stdio.h>
>>
>> int main(int argc, char **argv)
>> {
>>  char *a;
>>  sscanf(argv[1], "%as", &a);
>>  puts(a);
>>  return 0;
>> }
>> ~$ cc -Wall -c a.c
>> ~$ ./a "xx yy"
>> xx
>> ~$ gcc-2.95 -Wall -c a.c
>> ~$ gcc-3.3 -Wall -c a.c
>> ~$ gcc-3.4 -Wall -c a.c
>> ~$ gcc-4.1 -Wall -c a.c
>> ~$ gcc-4.2 -Wall -c a.c
>> ~$ gcc-4.3 -Wall -c a.c
>> ~$
>>
>> Seems OK.
>>
>> Maybe you had "%a" instead of "%as"?
>
> No, my problem was that my cc alias includes ansi c 99, which disables
> this scanf() feature...

Okay -- so %as is available by default, but disabled by -std=c99,
unless _GNU_SOURCE is also specified :-}



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #65 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 12:37:50 +0200
tags 487254 fixed-upstream
thanks

Stephane, both halves of this bug are now fixed.

Could you please review the following new text, which will appear in
man-pages 3.01.

Cheers,

Michael

   NOTES
       The GNU C library supports a non-standard extension that causes
       the library to dynamically allocate a string of sufficient size
       for  input  strings  for  the  %s  and   %a[range]   conversion
       specifiers.  To make use of this feature, specify a as a length
       modifier (thus %as or %a[range]).  The caller must free(3)  the
       returned string, as in the following example:

           char *p;

           scanf("%a[a-zA-Z]", &p);
           printf("%s0, p);
           free(p);

       This  feature  is not available if the program is compiled with
       cc -std=cc99 or cc -D_ISOC99_SOURCE (unless _GNU_SOURCE is also
       specified),  in  which case the a is interpreted as a specifier
       for floating point numbers (see above).

       Since version 2.7, glibc also provides the m modifier  for  the
       same purpose as the a modifier.  The m modifier has the follow-
       ing advantages:

       * It may also be applied to  %c  conversion  specifiers  (e.g.,
         %3mc).

       * It  avoids  ambiguity  with  respect to the %a floating-point
         conversion specifier (and is unaffected by cc -std=99 etc.)

       * It is specified in the upcoming revision of the POSIX.1 stan-
         dard.




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #70 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 12:15:42 +0100
On Mon, Jun 23, 2008 at 12:37:50PM +0200, Michael Kerrisk wrote:
[...]
>    NOTES
>        The GNU C library supports a non-standard extension that causes
>        the library to dynamically allocate a string of sufficient size
>        for  input  strings  for  the  %s  and   %a[range]   conversion
>        specifiers.  To make use of this feature, specify a as a length
>        modifier (thus %as or %a[range]).  The caller must free(3)  the
>        returned string, as in the following example:
> 
>            char *p;
> 
>            scanf("%a[a-zA-Z]", &p);

You need to check the return value of scanf (could be 0 or EOF,
caused by the absence of letters in the input, or an EOF or read
error or ENOMEM.

>            printf("%s0, p);

typo? printf("%s\n", p)

>            free(p);

That might free something unallocated.

>        This  feature  is not available if the program is compiled with
>        cc -std=cc99 or cc -D_ISOC99_SOURCE (unless _GNU_SOURCE is also
>        specified),  in  which case the a is interpreted as a specifier
>        for floating point numbers (see above).

Maybe "gcc" instead of "cc" as I don't expect all the cc
implementations to have such a -std option.

>        Since version 2.7, glibc also provides the m modifier  for  the
>        same purpose as the a modifier.  The m modifier has the follow-
>        ing advantages:
> 
>        * It may also be applied to  %c  conversion  specifiers  (e.g.,
>          %3mc).
> 
>        * It  avoids  ambiguity  with  respect to the %a floating-point
>          conversion specifier (and is unaffected by cc -std=99 etc.)
> 
>        * It is specified in the upcoming revision of the POSIX.1 stan-
>          dard.

Thanks for that, I hadn't thought of checking the draft.

I can see the draft makes it clear that you don't need to free
the buffer if scanf fails. I think it should be mentionned in
the man page as well as it seems to also be the case for %a.

So:

errno = 0;
n = scanf(..., &p);
if (n == 1) {
  printf("OK: %s\n", p);
  free(p);
} else if (errno != 0) {
  perror("scanf");
}
else {
  fprintf(stderr, "expected letters, not \"%s\"\n", ...);
}

-- 
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #75 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 12:31:39 +0100
On Mon, Jun 23, 2008 at 12:37:50PM +0200, Michael Kerrisk wrote:
[...]
>        This  feature  is not available if the program is compiled with
>        cc -std=cc99 or cc -D_ISOC99_SOURCE (unless _GNU_SOURCE is also
[...]

typo: -std=c99, not cc99.

-- 
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #80 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 13:34:04 +0200
On Mon, Jun 23, 2008 at 1:31 PM, Stephane Chazelas
<Stephane_Chazelas@yahoo.fr> wrote:
> On Mon, Jun 23, 2008 at 12:37:50PM +0200, Michael Kerrisk wrote:
> [...]
>>        This  feature  is not available if the program is compiled with
>>        cc -std=cc99 or cc -D_ISOC99_SOURCE (unless _GNU_SOURCE is also
> [...]
>
> typo: -std=c99, not cc99.

Thanks.  Fixed.  It sort of balanced out.  Elsewhere in the page I
wrote another typo: -std=99.

;-)

Cheers,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #85 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 12:43:25 +0100
On Mon, Jun 23, 2008 at 01:34:04PM +0200, Michael Kerrisk wrote:
> On Mon, Jun 23, 2008 at 1:31 PM, Stephane Chazelas
> <Stephane_Chazelas@yahoo.fr> wrote:
> > On Mon, Jun 23, 2008 at 12:37:50PM +0200, Michael Kerrisk wrote:
> > [...]
> >>        This  feature  is not available if the program is compiled with
> >>        cc -std=cc99 or cc -D_ISOC99_SOURCE (unless _GNU_SOURCE is also
> > [...]
> >
> > typo: -std=c99, not cc99.
> 
> Thanks.  Fixed.  It sort of balanced out.  Elsewhere in the page I
> wrote another typo: -std=99.
[...]

With tcc, you need the -D_GNU_SOURCE:

~$ cat a.c
#include <stdio.h>
int main()
{
  char *a = 0;
  int n;
  n = sscanf("test", "%as", &a);
  printf("%d %s\n", n, a);
  return 0;
}
~$ tcc -run ./a.c
0 (null)
~$ tcc -D_GNU_SOURCE -run ./a.c
1 test

~$ tcc a.c
~$ nm -D a.out |& grep scanf
         U __isoc99_sscanf

~$ tcc -D_GNU_SOURCE a.c
~$ nm -D a.out |& grep scanf
         U sscanf

On debian, cc can be tcc.

~$ update-alternatives --list cc
/usr/bin/gcc
/usr/bin/tcc

-- 
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #90 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 13:43:39 +0200
Hi Stephane,

On Mon, Jun 23, 2008 at 1:15 PM, Stephane Chazelas
<Stephane_Chazelas@yahoo.fr> wrote:
> On Mon, Jun 23, 2008 at 12:37:50PM +0200, Michael Kerrisk wrote:
> [...]
>>    NOTES
>>        The GNU C library supports a non-standard extension that causes
>>        the library to dynamically allocate a string of sufficient size
>>        for  input  strings  for  the  %s  and   %a[range]   conversion
>>        specifiers.  To make use of this feature, specify a as a length
>>        modifier (thus %as or %a[range]).  The caller must free(3)  the
>>        returned string, as in the following example:
>>
>>            char *p;
>>
>>            scanf("%a[a-zA-Z]", &p);
>
> You need to check the return value of scanf (could be 0 or EOF,
> caused by the absence of letters in the input, or an EOF or read
> error or ENOMEM.
>
>>            printf("%s0, p);
>
> typo? printf("%s\n", p)

Thanks for that.  Forgot to double the slash in the source.

>>            free(p);
>
> That might free something unallocated.

Good catch!  Thanks.

>>        This  feature  is not available if the program is compiled with
>>        cc -std=cc99 or cc -D_ISOC99_SOURCE (unless _GNU_SOURCE is also
>>        specified),  in  which case the a is interpreted as a specifier
>>        for floating point numbers (see above).
>
> Maybe "gcc" instead of "cc" as I don't expect all the cc
> implementations to have such a -std option.

Done.

>>        Since version 2.7, glibc also provides the m modifier  for  the
>>        same purpose as the a modifier.  The m modifier has the follow-
>>        ing advantages:
>>
>>        * It may also be applied to  %c  conversion  specifiers  (e.g.,
>>          %3mc).
>>
>>        * It  avoids  ambiguity  with  respect to the %a floating-point
>>          conversion specifier (and is unaffected by cc -std=99 etc.)
>>
>>        * It is specified in the upcoming revision of the POSIX.1 stan-
>>          dard.
>
> Thanks for that, I hadn't thought of checking the draft.

I only though of it because for a long time I had a FIXME in the
scanf.3 page saying "Document the m modifier!"

> I can see the draft makes it clear that you don't need to free
> the buffer if scanf fails. I think it should be mentionned in
> the man page as well as it seems to also be the case for %a.

Yes, good idea.

> So:
>
> errno = 0;
> n = scanf(..., &p);
> if (n == 1) {
>  printf("OK: %s\n", p);
>  free(p);
> } else if (errno != 0) {
>  perror("scanf");
> }
> else {
>  fprintf(stderr, "expected letters, not \"%s\"\n", ...);
> }

Thanks for that piece of code.  I'll include a version of that in the page.

Cheers,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #95 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 13:45:28 +0200
On Mon, Jun 23, 2008 at 1:43 PM, Stephane Chazelas
<Stephane_Chazelas@yahoo.fr> wrote:
> On Mon, Jun 23, 2008 at 01:34:04PM +0200, Michael Kerrisk wrote:
>> On Mon, Jun 23, 2008 at 1:31 PM, Stephane Chazelas
>> <Stephane_Chazelas@yahoo.fr> wrote:
>> > On Mon, Jun 23, 2008 at 12:37:50PM +0200, Michael Kerrisk wrote:
>> > [...]
>> >>        This  feature  is not available if the program is compiled with
>> >>        cc -std=cc99 or cc -D_ISOC99_SOURCE (unless _GNU_SOURCE is also
>> > [...]
>> >
>> > typo: -std=c99, not cc99.
>>
>> Thanks.  Fixed.  It sort of balanced out.  Elsewhere in the page I
>> wrote another typo: -std=99.
> [...]
>
> With tcc, you need the -D_GNU_SOURCE:

Thanks.  I don't think I'll worry about documenting that though.




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #100 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 13:47:59 +0200
Right, here's another version.  Could you please have another read
through, Stephane

   NOTES
       The GNU C library supports a non-standard extension that causes
       the library to dynamically allocate a string of sufficient size
       for  input  strings  for  the  %s  and   %a[range]   conversion
       specifiers.  To make use of this feature, specify a as a length
       modifier (thus %as or %a[range]).  The caller must free(3)  the
       returned string, as in the following example:

           char *p;
           int n;

           errno = 0;
           n = scanf("%a[a-z]", &p);
           printf("n=%d, errno=%d\n", n, errno);
           if (n == 1) {
               printf("read: %s\n", p);
               free(p);
           } else if (errno != 0) {
               perror("scanf");
           } else {
               fprintf(stderr, "No matching characters\n"):
           }

       As  shown  in  the  above example, it is only necessary to call
       free(3) if the scanf() call successfully read a string.

       The a modifier is not available if the program is compiled with
       gcc  -std=c99  or  gcc  -D_ISOC99_SOURCE (unless _GNU_SOURCE is
       also specified), in which case the a is interpreted as a speci-
       fier for floating point numbers (see above).

       Since  version  2.7, glibc also provides the m modifier for the
       same purpose as the a modifier.  The m modifier has the follow-
       ing advantages:

       * It  may  also  be  applied to %c conversion specifiers (e.g.,
         %3mc).

       * It avoids ambiguity with respect  to  the  %a  floating-point
         conversion specifier (and is unaffected by gcc -std=c99 etc.)

       * It is specified in the upcoming revision of the POSIX.1 stan-
         dard.




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #105 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 12:52:34 +0100
On Mon, Jun 23, 2008 at 01:43:39PM +0200, Michael Kerrisk wrote:
[...]
> > errno = 0;
> > n = scanf(..., &p);
> > if (n == 1) {
> >  printf("OK: %s\n", p);
> >  free(p);
> > } else if (errno != 0) {
> >  perror("scanf");
> > }
> > else {
> >  fprintf(stderr, "expected letters, not \"%s\"\n", ...);

Well, that error message would be OK for sscanf where you could
use the scanned string for the %s above, but not for scanf,
sorry.

> > }
> 
> Thanks for that piece of code.  I'll include a version of that in the page.
[...]

One may also want to check for (n == EOF), though it's OK to
treat n == 0 and n == EOF the same when you only need to check
the correctness of the input (n==EOF means empty input).

-- 
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #110 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 13:52:07 +0100
On Mon, Jun 23, 2008 at 01:45:28PM +0200, Michael Kerrisk wrote:
> On Mon, Jun 23, 2008 at 1:43 PM, Stephane Chazelas
> <Stephane_Chazelas@yahoo.fr> wrote:
> > On Mon, Jun 23, 2008 at 01:34:04PM +0200, Michael Kerrisk wrote:
> >> On Mon, Jun 23, 2008 at 1:31 PM, Stephane Chazelas
> >> <Stephane_Chazelas@yahoo.fr> wrote:
> >> > On Mon, Jun 23, 2008 at 12:37:50PM +0200, Michael Kerrisk wrote:
> >> > [...]
> >> >>        This  feature  is not available if the program is compiled with
> >> >>        cc -std=cc99 or cc -D_ISOC99_SOURCE (unless _GNU_SOURCE is also
> >> > [...]
> >> >
> >> > typo: -std=c99, not cc99.
> >>
> >> Thanks.  Fixed.  It sort of balanced out.  Elsewhere in the page I
> >> wrote another typo: -std=99.
> > [...]
> >
> > With tcc, you need the -D_GNU_SOURCE:
> 
> Thanks.  I don't think I'll worry about documenting that though.

Hmmm, in stdio.h, we have:

#if defined __USE_ISOC99 && !defined __USE_GNU \
    && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
    && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)
# ifdef __REDIRECT
/* For strict ISO C99 or POSIX compliance disallow %as, %aS and %a[
   GNU extension which conflicts with valid %a followed by letter
   s, S or [.  */
extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
                                __const char *__restrict __format, ...),
                       __isoc99_fscanf) __wur;
extern int __REDIRECT (scanf, (__const char *__restrict __format, ...),
                       __isoc99_scanf) __wur;
extern int __REDIRECT (sscanf, (__const char *__restrict __s,
                                __const char *__restrict __format, ...),
                       __isoc99_sscanf) __THROW;


Which looks a bit bogus to me (see the handling of __REDIRECT
for instance).

__STRICT_ANSI__ is selected by -std=c99 and -ansi.
__USE_XOPEN2K (XPG6) is selected when __POSIX_C_SOURCE >= 200112L
which is selected by:

/* If none of the ANSI/POSIX macros are defined, use POSIX.1 and POSIX.2
   (and IEEE Std 1003.1b-1993 unless _XOPEN_SOURCE is defined).  */
#if ((!defined __STRICT_ANSI__ || (_XOPEN_SOURCE - 0) >= 500) && \
     !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE)
# define _POSIX_SOURCE  1
# if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 500
#  define _POSIX_C_SOURCE       2
# elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 600
#  define _POSIX_C_SOURCE       199506L
# else
#  define _POSIX_C_SOURCE       200112L
# endif
#endif


So, %as is not available for instance with:

cc -D__STDC_VERSION__=199901L
(tcc does set that as a builtin macro
http://hg.sharesource.org/mercurialtcc/rev/1e81d5b65878)

And it is availabe for instance with

cc -D_ISOC99_SOURCE -D_XOPEN_SOURCE=500

Without any implicit define, %as will be enabled I think.

-- 
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #115 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 14:13:49 +0100
On Mon, Jun 23, 2008 at 01:47:59PM +0200, Michael Kerrisk wrote:
> Right, here's another version.  Could you please have another read
> through, Stephane

Michael,

it looks good to me.

I suspect it wasn't your intention to leave
>            printf("n=%d, errno=%d\n", n, errno);
in though. That printf might set errno itself so that the next
check for errno wouldn't be valid.


> 
>    NOTES
>        The GNU C library supports a non-standard extension that causes
>        the library to dynamically allocate a string of sufficient size
>        for  input  strings  for  the  %s  and   %a[range]   conversion
>        specifiers.  To make use of this feature, specify a as a length
>        modifier (thus %as or %a[range]).  The caller must free(3)  the
>        returned string, as in the following example:
> 
>            char *p;
>            int n;
> 
>            errno = 0;
>            n = scanf("%a[a-z]", &p);
>            printf("n=%d, errno=%d\n", n, errno);
>            if (n == 1) {
>                printf("read: %s\n", p);
>                free(p);
>            } else if (errno != 0) {
>                perror("scanf");
>            } else {
>                fprintf(stderr, "No matching characters\n"):
>            }
> 
>        As  shown  in  the  above example, it is only necessary to call
>        free(3) if the scanf() call successfully read a string.
> 
>        The a modifier is not available if the program is compiled with
>        gcc  -std=c99  or  gcc  -D_ISOC99_SOURCE (unless _GNU_SOURCE is
>        also specified), in which case the a is interpreted as a speci-
>        fier for floating point numbers (see above).
> 
>        Since  version  2.7, glibc also provides the m modifier for the
>        same purpose as the a modifier.  The m modifier has the follow-
>        ing advantages:
> 
>        * It  may  also  be  applied to %c conversion specifiers (e.g.,
>          %3mc).
> 
>        * It avoids ambiguity with respect  to  the  %a  floating-point
>          conversion specifier (and is unaffected by gcc -std=c99 etc.)
> 
>        * It is specified in the upcoming revision of the POSIX.1 stan-
>          dard.

Cheers,
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to "Michael Kerrisk" <mtk.manpages@googlemail.com>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #120 received at 487254@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Stephane Chazelas" <Stephane_Chazelas@yahoo.fr>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 15:18:49 +0200
On Mon, Jun 23, 2008 at 3:13 PM, Stephane Chazelas
<Stephane_Chazelas@yahoo.fr> wrote:
> On Mon, Jun 23, 2008 at 01:47:59PM +0200, Michael Kerrisk wrote:
>> Right, here's another version.  Could you please have another read
>> through, Stephane
>
> Michael,
>
> it looks good to me.
>
> I suspect it wasn't your intention to leave
>>            printf("n=%d, errno=%d\n", n, errno);

D'oh!

Thanks.  Gone now.


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #125 received at 487254@bugs.debian.org (full text, mbox):

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: 487254@bugs.debian.org
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 14:27:57 +0100
On Mon, Jun 23, 2008 at 01:52:07PM +0100, Stephane Chazelas wrote:
[...]
> So, %as is not available for instance with:
> 
> cc -D__STDC_VERSION__=199901L
> (tcc does set that as a builtin macro
> http://hg.sharesource.org/mercurialtcc/rev/1e81d5b65878)
[...]

FYI, and I'm getting off-topic here, the rationale for tcc
setting __STDC_VERSION__ to 199901L can be found in glibc's
features.h:

/* Decide whether a compiler supports the long long datatypes.  */
#if defined __GNUC__ \
    || (defined __PGI && defined __i386__ ) \
    || (defined __INTEL_COMPILER && (defined __i386__ || defined __ia64__)) \
    || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
# define __GLIBC_HAVE_LONG_LONG 1
#endif


So any non-GNU compiler that supports "long long" would have to
set __STDC_VERSION__ to something >= 199901L

So with any such compiler, you'd need to #define _GNU_SOURCE to
have access to %as. In any case it makes sense to use
_GNU_SOURCE given that it *is* a GNU extension.

Best regards,
Stéphane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#487254; Package manpages-dev. Full text and rfc822 format available.

Acknowledgement sent to Joey Schulze <joey@infodrom.org>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #130 received at 487254@bugs.debian.org (full text, mbox):

From: Joey Schulze <joey@infodrom.org>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>, 487254@bugs.debian.org, "Wichmann, Mats D" <mats.d.wichmann@intel.com>
Subject: Re: Bug#487254: manpages-dev: *scanf may set errno to ERANGE
Date: Mon, 23 Jun 2008 20:38:45 +0200
Michael Kerrisk wrote:
> > But I'm not sure if that's a bug or not as I don't know whether
> > manpages-dev is meant to document the GNU or other version of
> > the libc functions.
> 
> I don't know that manpages-dev has a policy on that.  Upstream
> man-pages policy is: yes, document glibc specifics (but give context
> re portability).

For Debian manpages the same policy applies.

> > BTW, Michael, I take it you're the maintainer of the
> > manpages-dev debian package,
> 
> Sometimes one could get that impression ;-).  But, no, I'm not.  I'm
> merely the upstream maintainer.  (Debain derives the downstream
> manpages and manpages-dev packages from my upstream man-pages.  The
> Debian maintainer is Joey.)

I'm very glad Michael is so active.  A lot of bug reports are not
Debian specific and this way the information is passed upstream
directly.

> > What's the debian view on the LSB.
> 
> I don't know.

In general the Debian project wishes to support the current version of
LSB.  However, this is best discussed on the debian-lsb list that runs
on lists.debian.org.

Regards,

	Joey

-- 
Everybody talks about it, but nobody does anything about it!  -- Mark Twain

Please always Cc to me when replying to me on the lists.




Reply sent to Joey Schulze <joey@infodrom.org>:
You have taken responsibility. Full text and rfc822 format available.

Notification sent to Stephane Chazelas <stephane_chazelas@yahoo.fr>:
Bug acknowledged by developer. Full text and rfc822 format available.

Message #135 received at 487254-close@bugs.debian.org (full text, mbox):

From: Joey Schulze <joey@infodrom.org>
To: 487254-close@bugs.debian.org
Subject: Bug#487254: fixed in manpages 3.01-1
Date: Fri, 27 Jun 2008 13:32:04 +0000
Source: manpages
Source-Version: 3.01-1

We believe that the bug you reported is fixed in the latest version of
manpages, which is due to be installed in the Debian FTP archive:

manpages-dev_3.01-1_all.deb
  to pool/main/m/manpages/manpages-dev_3.01-1_all.deb
manpages_3.01-1.diff.gz
  to pool/main/m/manpages/manpages_3.01-1.diff.gz
manpages_3.01-1.dsc
  to pool/main/m/manpages/manpages_3.01-1.dsc
manpages_3.01-1_all.deb
  to pool/main/m/manpages/manpages_3.01-1_all.deb
manpages_3.01.orig.tar.gz
  to pool/main/m/manpages/manpages_3.01.orig.tar.gz



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 487254@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Joey Schulze <joey@infodrom.org> (supplier of updated manpages package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Fri, 27 Jun 2008 15:11:49 +0200
Source: manpages
Binary: manpages manpages-dev
Architecture: source all
Version: 3.01-1
Distribution: unstable
Urgency: low
Maintainer: Martin Schulze <joey@debian.org>
Changed-By: Joey Schulze <joey@infodrom.org>
Description: 
 manpages   - Manual pages about using a GNU/Linux system
 manpages-dev - Manual pages about using GNU/Linux for development
Closes: 482979 482987 485636 486920 487254
Changes: 
 manpages (3.01-1) unstable; urgency=low
 .
   * New upstream version
     . inet_aton() is *not* in POSIX.1 (closes: Bug#482979)
     . Improvements to inet_pton() (closes: Bug#482987)
     . Improvements to nanosleep(2) (closes: Bug#485636)
     . Added errors section for scanf(3) (closes: Bug#487254)
     . Document guest time in proc(5) (closes: Bug#486920)
Checksums-Sha1: 
 1605e0806dc4854d3379150ffbb4e9b0eeed5d40 964 manpages_3.01-1.dsc
 cfd01d341b259d44f8391789457d52e38bc8d327 1348851 manpages_3.01.orig.tar.gz
 22fc4b999ed541f1a17373b152680cb362ecaa8c 46423 manpages_3.01-1.diff.gz
 a6379d90da5015dff07767be4223f9699c5d2610 577032 manpages_3.01-1_all.deb
 feb3784e22d92755113345b12d4c786c03a74a2e 1403326 manpages-dev_3.01-1_all.deb
Checksums-Sha256: 
 a7829005f845c3a710d597bbc5d46987f6109d1d50481ed0a27f1892442e2735 964 manpages_3.01-1.dsc
 04ff9d05a43c5820a1127efba6caf06a6ba9bd9a98c18cd93f38ff3446c7c236 1348851 manpages_3.01.orig.tar.gz
 c3352a5cb9c80f0fdf88fb29c3011397177186d45b856eb8cc0341b8fc2ac156 46423 manpages_3.01-1.diff.gz
 8104d0c7bde81f81d52a85ba20bec58f2d58ae108fb8f37f4cdebdf2811ba1e7 577032 manpages_3.01-1_all.deb
 e7da5ca23627565dce0fb8c77ea3f248408f8b9bf4d83d67f626e94f9cb0d0e8 1403326 manpages-dev_3.01-1_all.deb
Files: 
 0ce201ebec8b8d10bc745683d6a525fc 964 doc important manpages_3.01-1.dsc
 5afc311cf7b96d08e17af30f566b1887 1348851 doc important manpages_3.01.orig.tar.gz
 f2d94a71cc35c7dc99d0cd48d63480d4 46423 doc important manpages_3.01-1.diff.gz
 1d8ffc83c891573da6bcbc04a5043982 577032 doc important manpages_3.01-1_all.deb
 68a2acbedea8fde5d3e4bedb06a6aaa6 1403326 doc optional manpages-dev_3.01-1_all.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFIZOfHW5ql+IAeqTIRAnIJAJ9liGLBOO9JmDmBuWCRH6Acgi0ThQCfe4AO
VpHRgibtbO0kTIl+qz19MDU=
=EyFw
-----END PGP SIGNATURE-----





Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Thu, 07 Aug 2008 07:31:02 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Fri Apr 18 10:48:40 2014; Machine Name: buxtehude.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.