Skip to content

Commit

Permalink
[master] Merge branch 'bug21-longmax'
Browse files Browse the repository at this point in the history
  • Loading branch information
pcherenkov committed Dec 2, 2020
2 parents 0abc26e + 583ec32 commit a955a6b
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions chipmunk/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ static char s_sysinfo [1024] = "\0";

extern struct udpxy_opt g_uopt;

/* NB: use LLONG_MAX and LLONG_MIN recommended when
* compiling with C99 compliance;
*
* we still (yet) complie under C89, so LLONGMAX64,
* LLONGMIN64 are introduced instead to avoid C99-related
* warnings
*/

# define LLONGMAX64 9223372036854775807.0
# define LLONGMIN64 (-LLONGMAX64 - 1.0)

/* write buffer to a file
*
*/
Expand Down Expand Up @@ -845,7 +856,7 @@ a2double( const char* str, double* pval )


int
a2size( const char* str, ssize_t* pval )
a2int64( const char* str, int64_t* pval )
{
double dval = 0.0;
int rc = 0;
Expand All @@ -854,47 +865,31 @@ a2size( const char* str, ssize_t* pval )
if( 0 != (rc = a2double( str, &dval )) )
return rc;

if( dval > LONG_MAX || dval < LONG_MIN )
if( dval > LLONGMAX64 || dval < LLONGMIN64 )
return ERR_OVFLW;

if( NULL != pval ) {
*pval = (ssize_t)dval;
*pval = (int64_t)dval;
}

return rc;
}


int
a2int64( const char* str, int64_t* pval )
a2size( const char* str, ssize_t* pval )
{
/* NB: use LLONG_MAX and LLONG_MIN recommended when
* compiling with C99 compliance;
*
* we still (yet) complie under C89, so LLONGMAX64,
* LLONGMIN64 are introduced instead to avoid C99-related
* warnings
*/

# define LLONGMAX64 9223372036854775807.0
# define LLONGMIN64 (-LLONGMAX64 - 1.0)

double dval = 0.0;
int rc = 0;
static const int ERR_OVFLW = -2;

if( 0 != (rc = a2double( str, &dval )) )
return rc;

if( dval > LLONGMAX64 || dval < LLONGMIN64 )
return ERR_OVFLW;
int64_t n64 = 0;
int rc = a2int64(str, &n64);

if( NULL != pval ) {
*pval = (int64_t)dval;
if (pval && 0 == rc) {
*pval = (ssize_t)n64;
}

return rc;
}


/* returns asctime w/o CR character at the end
*/
const char*
Expand Down

0 comments on commit a955a6b

Please sign in to comment.