develooper Front page | perl.perl5.porters | Postings from February 2011

Re: [perl #84680] POSIX::isdigit() returns 1 for the empty string

Thread Previous | Thread Next
From:
Steve Peters
Date:
February 24, 2011 20:05
Subject:
Re: [perl #84680] POSIX::isdigit() returns 1 for the empty string
Message ID:
AANLkTimA45L3GYrzLyhzJtTYv1a5=L0_LDoOGQPhuSnQ@mail.gmail.com
On Tue, Feb 22, 2011 at 10:27 AM, Robert Lang <perlbug-followup@perl.org>wrote:

> # New Ticket Created by  Robert Lang
> # Please include the string:  [perl #84680]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=84680 >
>
>
> This is a bug report for perl from perlbug@cg.cjb.net,
> generated with the help of perlbug 1.39 running under perl 5.12.3.
>
>
> -----------------------------------------------------------------
> [Please describe your issue here]
>
> POSIX::isdigit() returns 1 for the empty string which is
> obviously wrong:
>
> $ perl -MPOSIX -e 'print isdigit(""), "\n"'
> 1
> $
>
> That's probably because RETVAL is initialised to 1 in POSIX.xs
> regardless of the string length (which is the case in all is*()
> functions ...).
>
> Verified with Perl 5.8.8, 5.10.1 and 5.12.3
>
>
Thanks for the report.  I do have a fix ready for this, but before I commit
this, this technically effects all the ifXXX() functions.  Also, in the
ext/POSIX/t/posix.t we have...

# metaphysical question : what should be returned for an empty string ?
# anyway this shouldn't segfault (bug #24554)
ok( POSIX::isalnum(''),   'isalnum empty string' );
ok( POSIX::isalnum(undef),'isalnum undef' );

For this following basic C program...

#include <ctype.h>
#include <stdio.h>

int
main() {
    char* aiieee = "";
    int crr_aaack = isdigit(foo);
    printf("%d\n", crr_aaack);
}

Linux core dumps while MAC OS X prints 0.  Trying...

char aiieee = '';

instead fails to compile.  If I'm following the spirit of C, then I'm
thinking passing an empty string or undef to the isXXX() functions should
return 0.

Steve Peters
steve@fisharerojo.org

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About