X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2F_PDCLIB%2Fstrtox_prelim.c;h=d36837e49ae911369009643e7b383a88c18dc373;hb=b42a534f135f12fe47a6bc343bb6cc2c0e973198;hp=8b0f44236317d8d7217a647c67f6e2843783a222;hpb=f66fc2a4fc1b45e0aa357f2dd0e45ddd1b7c9142;p=pdclib.old diff --git a/functions/_PDCLIB/strtox_prelim.c b/functions/_PDCLIB/strtox_prelim.c index 8b0f442..d36837e 100644 --- a/functions/_PDCLIB/strtox_prelim.c +++ b/functions/_PDCLIB/strtox_prelim.c @@ -1,7 +1,5 @@ /* $Id$ */ -/* Release $Name$ */ - /* _PDCLIB_strtox_prelim( const char *, char *, int * ) This file is part of the Public Domain C Library (PDCLib). @@ -9,6 +7,7 @@ */ #include +#include const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base ) { @@ -39,20 +38,19 @@ const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base ) { *base = 10; } - return p; + return ( ( *base >= 2 ) && ( *base <= 36 ) ) ? p : NULL; } #ifdef TEST #include <_PDCLIB_test.h> -int main() +int main( void ) { int base = 0; char sign = '\0'; char test1[] = " 123"; char test2[] = "\t+0123"; char test3[] = "\v-0x123"; - BEGIN_TESTS; TESTCASE( _PDCLIB_strtox_prelim( test1, &sign, &base ) == &test1[2] ); TESTCASE( sign == '+' ); TESTCASE( base == 10 ); @@ -71,6 +69,10 @@ int main() TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == &test3[2] ); TESTCASE( sign == '-' ); TESTCASE( base == 10 ); + base = 1; + TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL ); + base = 37; + TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL ); return TEST_RESULTS; }