POSIX::isXXX(undef) segfaulted. (bug #24554.)
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sat, 29 Nov 2003 11:38:58 +0000 (11:38 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sat, 29 Nov 2003 11:38:58 +0000 (11:38 +0000)
p4raw-id: //depot/perl@21802

ext/POSIX/POSIX.xs
ext/POSIX/t/posix.t

index 54e087a..6a509b9 100644 (file)
@@ -845,7 +845,7 @@ isalnum(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!isalnum(*s))
                RETVAL = 0;
@@ -857,7 +857,7 @@ isalpha(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!isalpha(*s))
                RETVAL = 0;
@@ -869,7 +869,7 @@ iscntrl(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!iscntrl(*s))
                RETVAL = 0;
@@ -881,7 +881,7 @@ isdigit(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!isdigit(*s))
                RETVAL = 0;
@@ -893,7 +893,7 @@ isgraph(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!isgraph(*s))
                RETVAL = 0;
@@ -905,7 +905,7 @@ islower(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!islower(*s))
                RETVAL = 0;
@@ -917,7 +917,7 @@ isprint(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!isprint(*s))
                RETVAL = 0;
@@ -929,7 +929,7 @@ ispunct(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!ispunct(*s))
                RETVAL = 0;
@@ -941,7 +941,7 @@ isspace(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!isspace(*s))
                RETVAL = 0;
@@ -953,7 +953,7 @@ isupper(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!isupper(*s))
                RETVAL = 0;
@@ -965,7 +965,7 @@ isxdigit(charstring)
        unsigned char * charstring
     CODE:
        unsigned char *s = charstring;
-       unsigned char *e = s + SvCUR(ST(0));
+       unsigned char *e = SvPOK(ST(0)) ? s + SvCUR(ST(0)) : (unsigned char*)0;
        for (RETVAL = 1; RETVAL && s < e; s++)
            if (!isxdigit(*s))
                RETVAL = 0;
index f8339f7..912b3d8 100644 (file)
@@ -11,7 +11,7 @@ BEGIN {
 }
 
 require "./test.pl";
-plan(tests => 61);
+plan(tests => 63);
 
 use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write
             errno);
@@ -259,6 +259,10 @@ ok( POSIX::isspace("\t"), 'isspace' );
 ok(!POSIX::isspace('_'),  'isspace' );
 ok( POSIX::isxdigit('f'), 'isxdigit' );
 ok(!POSIX::isxdigit('g'), 'isxdigit' );
+# 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' );
  
 # Check that output is not flushed by _exit. This test should be last
 # in the file, and is not counted in the total number of tests.