Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions functions/_PDCLIB/_PDCLIB_strtox_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

#ifndef REGTEST

_PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, uintmax_t error, uintmax_t limval, int limdigit, char * sign )
_PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, uintmax_t error, uintmax_t limit, char * sign )
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file header comment at line 1 needs to be updated to reflect the new function signature. It currently shows the old signature with 5 parameters (limval and limdigit as separate int parameters), but the function now takes 4 parameters after the base plus the sign pointer, with limit replacing limval and limdigit.

Copilot uses AI. Check for mistakes.
{
_PDCLIB_uintmax_t rc = 0;
int digit = -1;
const char * x;
_PDCLIB_uintmax_t limval = limit / base;
int limdigit = limit % base;

while ( ( x = (const char *)memchr( _PDCLIB_digits, tolower( (unsigned char)**p ), base ) ) != NULL )
{
Expand Down Expand Up @@ -70,25 +72,25 @@ int main( void )
/* basic functionality */
p = test;
errno = 0;
TESTCASE( _PDCLIB_strtox_main( &p, 10u, ( uintmax_t )999, ( uintmax_t )12, 3, &sign ) == 123 );
TESTCASE( _PDCLIB_strtox_main( &p, 10u, ( uintmax_t )999, ( uintmax_t )999, &sign ) == 123 );
TESTCASE( errno == 0 );
TESTCASE( p == &test[3] );
/* proper functioning to smaller base */
p = test;
TESTCASE( _PDCLIB_strtox_main( &p, 8u, ( uintmax_t )999, ( uintmax_t )12, 3, &sign ) == 0123 );
TESTCASE( _PDCLIB_strtox_main( &p, 8u, ( uintmax_t )999, ( uintmax_t )999, &sign ) == 0123 );
TESTCASE( errno == 0 );
TESTCASE( p == &test[3] );
/* overflowing subject sequence must still return proper endptr */
p = test;
TESTCASE( _PDCLIB_strtox_main( &p, 4u, ( uintmax_t )999, ( uintmax_t )1, 2, &sign ) == 999 );
TESTCASE( _PDCLIB_strtox_main( &p, 4u, ( uintmax_t )999, ( uintmax_t )6, &sign ) == 999 );
TESTCASE( errno == ERANGE );
TESTCASE( p == &test[3] );
TESTCASE( sign == '+' );
/* testing conversion failure */
errno = 0;
p = fail;
sign = '-';
TESTCASE( _PDCLIB_strtox_main( &p, 10u, ( uintmax_t )999, ( uintmax_t )99, 8, &sign ) == 0 );
TESTCASE( _PDCLIB_strtox_main( &p, 10u, ( uintmax_t )999, ( uintmax_t )999, &sign ) == 0 );
TESTCASE( p == NULL );
#endif
return TEST_RESULTS;
Expand Down
4 changes: 2 additions & 2 deletions functions/inttypes/strtoimax.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ intmax_t strtoimax( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict

if ( sign == '+' )
{
rc = ( intmax_t )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )INTMAX_MAX, ( uintmax_t )( INTMAX_MAX / base ), ( int )( INTMAX_MAX % base ), &sign );
rc = ( intmax_t )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )INTMAX_MAX, ( uintmax_t )INTMAX_MAX, &sign );
}
else
{
rc = ( intmax_t )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )INTMAX_MIN, ( uintmax_t )( INTMAX_MIN / -base ), ( int )( -( INTMAX_MIN % base ) ), &sign );
rc = ( intmax_t )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )INTMAX_MIN, ( ( uintmax_t )INTMAX_MAX + 1 ), &sign );
}

if ( endptr != NULL )
Expand Down
2 changes: 1 addition & 1 deletion functions/inttypes/strtoumax.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ uintmax_t strtoumax( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restric
return 0;
}

rc = _PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )UINTMAX_MAX, ( uintmax_t )( UINTMAX_MAX / base ), ( int )( UINTMAX_MAX % base ), &sign );
rc = _PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )UINTMAX_MAX, ( uintmax_t )UINTMAX_MAX, &sign );

if ( endptr != NULL )
{
Expand Down
4 changes: 2 additions & 2 deletions functions/stdlib/strtol.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ long int strtol( const char * s, char ** endptr, int base )

if ( sign == '+' )
{
rc = ( long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )LONG_MAX, ( uintmax_t )( LONG_MAX / base ), ( int )( LONG_MAX % base ), &sign );
rc = ( long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )LONG_MAX, ( uintmax_t )LONG_MAX, &sign );
}
else
{
rc = ( long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )LONG_MIN, ( uintmax_t )( LONG_MIN / -base ), ( int )( -( LONG_MIN % base ) ), &sign );
rc = ( long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )( unsigned long )LONG_MIN, ( ( uintmax_t )LONG_MAX + 1 ), &sign );
}

if ( endptr != NULL )
Expand Down
4 changes: 2 additions & 2 deletions functions/stdlib/strtoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ long long int strtoll( const char * s, char ** endptr, int base )

if ( sign == '+' )
{
rc = ( long long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )LLONG_MAX, ( uintmax_t )( LLONG_MAX / base ), ( int )( LLONG_MAX % base ), &sign );
rc = ( long long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )LLONG_MAX, ( uintmax_t )LLONG_MAX, &sign );
}
else
{
rc = ( long long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )LLONG_MIN, ( uintmax_t )( LLONG_MIN / -base ), ( int )( -( LLONG_MIN % base ) ), &sign );
rc = ( long long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )( unsigned long long )LLONG_MIN, ( ( uintmax_t )LLONG_MAX + 1 ), &sign );
}

if ( endptr != NULL )
Expand Down
2 changes: 1 addition & 1 deletion functions/stdlib/strtoul.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unsigned long int strtoul( const char * s, char ** endptr, int base )
return 0;
}

rc = ( unsigned long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )ULONG_MAX, ( uintmax_t )( ULONG_MAX / base ), ( int )( ULONG_MAX % base ), &sign );
rc = ( unsigned long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )ULONG_MAX, ( uintmax_t )ULONG_MAX, &sign );

if ( endptr != NULL )
{
Expand Down
2 changes: 1 addition & 1 deletion functions/stdlib/strtoull.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unsigned long long int strtoull( const char * s, char ** endptr, int base )
return 0;
}

rc = _PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )ULLONG_MAX, ( uintmax_t )( ULLONG_MAX / base ), ( int )( ULLONG_MAX % base ), &sign );
rc = _PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )ULLONG_MAX, ( uintmax_t )ULLONG_MAX, &sign );

if ( endptr != NULL )
{
Expand Down
2 changes: 1 addition & 1 deletion include/pdclib/_PDCLIB_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ _PDCLIB_LOCAL _PDCLIB_intmax_t _PDCLIB_atomax( const char * s );

/* Two helper functions used by strtol(), strtoul() and long long variants. */
_PDCLIB_LOCAL const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base );
_PDCLIB_LOCAL _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, _PDCLIB_uintmax_t error, _PDCLIB_uintmax_t limval, int limdigit, char * sign );
_PDCLIB_LOCAL _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, _PDCLIB_uintmax_t error, _PDCLIB_uintmax_t limit, char * sign );

/* Helper function used by strtof(), strtod(), and strtold(). */
_PDCLIB_LOCAL int _PDCLIB_strtod_prelim( const char * p, char * sign, char ** endptr );
Expand Down
Loading