From: Rafael Garcia-Suarez Date: Sat, 29 Nov 2003 11:38:58 +0000 (+0000) Subject: POSIX::isXXX(undef) segfaulted. (bug #24554.) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=117206bb8d8e2af3a310913a670836bd2f8023df;p=p5sagit%2Fp5-mst-13.2.git POSIX::isXXX(undef) segfaulted. (bug #24554.) p4raw-id: //depot/perl@21802 --- diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index 54e087a..6a509b9 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -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; diff --git a/ext/POSIX/t/posix.t b/ext/POSIX/t/posix.t index f8339f7..912b3d8 100644 --- a/ext/POSIX/t/posix.t +++ b/ext/POSIX/t/posix.t @@ -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.