mirror of
https://github.com/curl/curl.git
synced 2026-08-25 10:43:34 +03:00
lib: eliminate size_t casts
Add new functions in `curlx/warnless.h` for controlled type conversions: * curlx_uitouz, convert unsigned into to size_t (should always work) * curlx_uztoso, convert size_t to curl_off_t, capping at CURL_OFF_T_MAX * curlx_sztouz, convert ssize_t to size_t, return TRUE when ok * curlx_sotouz_range, convert curl_off_t to size_t interval, capping values to interval bounds Remove some unnecesary casts, convert some internal recv functions to the "return result, have size_t* arg" pattern. Closes #19495
This commit is contained in:
parent
78a610cb83
commit
cb2bcb681f
13 changed files with 170 additions and 156 deletions
|
|
@ -290,3 +290,38 @@ size_t curlx_sitouz(int sinum)
|
|||
# pragma warning(pop)
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t curlx_uitouz(unsigned int uinum)
|
||||
{
|
||||
return (size_t)uinum;
|
||||
}
|
||||
|
||||
size_t curlx_sotouz_range(curl_off_t sonum, size_t uzmin, size_t uzmax)
|
||||
{
|
||||
if(sonum < 0)
|
||||
return uzmin;
|
||||
#if SIZEOF_CURL_OFF_T > SIZEOF_SIZE_T
|
||||
if(sonum > SIZE_MAX)
|
||||
return uzmax;
|
||||
#endif
|
||||
return CURLMIN(CURLMAX((size_t)sonum, uzmin), uzmax);
|
||||
}
|
||||
|
||||
bool curlx_sztouz(ssize_t sznum, size_t *puznum)
|
||||
{
|
||||
if(sznum < 0) {
|
||||
*puznum = 0;
|
||||
return FALSE;
|
||||
}
|
||||
*puznum = (size_t)sznum;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
curl_off_t curlx_uztoso(size_t uznum)
|
||||
{
|
||||
#if SIZEOF_SIZE_T >= SIZEOF_CURL_OFF_T
|
||||
if(uznum > (size_t)CURL_OFF_T_MAX)
|
||||
return CURL_OFF_T_MAX;
|
||||
#endif
|
||||
return (curl_off_t)uznum;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue