lib: silence -Wsign-conversion in base64, strcase, mprintf

Closes #13467
This commit is contained in:
Viktor Szakats 2024-04-24 19:34:12 +02:00
parent 1972588d26
commit 03cf1c7b8c
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
3 changed files with 22 additions and 20 deletions

View File

@ -243,7 +243,7 @@ static CURLcode base64_encode(const char *table64,
*outptr = base64data; *outptr = base64data;
/* Return the length of the new data */ /* Return the length of the new data */
*outlen = output - base64data; *outlen = (size_t)(output - base64data);
return CURLE_OK; return CURLE_OK;
} }

View File

@ -77,7 +77,7 @@ static const char upper_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define OUTCHAR(x) \ #define OUTCHAR(x) \
do { \ do { \
if(!stream(x, userp)) \ if(!stream((unsigned char)x, userp)) \
done++; \ done++; \
else \ else \
return done; /* return on failure */ \ return done; /* return on failure */ \
@ -243,7 +243,7 @@ static int parsefmt(const char *format,
struct va_input *iptr; struct va_input *iptr;
bool loopit = TRUE; bool loopit = TRUE;
fmt++; fmt++;
outlen = fmt - start - 1; outlen = (size_t)(fmt - start - 1);
if(*fmt == '%') { if(*fmt == '%') {
/* this means a %% that should be output only as %. Create an output /* this means a %% that should be output only as %. Create an output
segment. */ segment. */
@ -261,7 +261,8 @@ static int parsefmt(const char *format,
continue; /* while */ continue; /* while */
} }
flags = width = precision = 0; flags = 0;
width = precision = 0;
if(use_dollar != DOLLAR_NOPE) { if(use_dollar != DOLLAR_NOPE) {
param = dollarstring(fmt, &fmt); param = dollarstring(fmt, &fmt);
@ -291,7 +292,7 @@ static int parsefmt(const char *format,
break; break;
case '-': case '-':
flags |= FLAGS_LEFT; flags |= FLAGS_LEFT;
flags &= ~FLAGS_PAD_NIL; flags &= ~(unsigned int)FLAGS_PAD_NIL;
break; break;
case '#': case '#':
flags |= FLAGS_ALT; flags |= FLAGS_ALT;
@ -549,7 +550,7 @@ static int parsefmt(const char *format,
optr = &out[ocount++]; optr = &out[ocount++];
if(ocount > MAX_SEGMENTS) if(ocount > MAX_SEGMENTS)
return PFMT_MANYSEGS; return PFMT_MANYSEGS;
optr->input = param; optr->input = (unsigned int)param;
optr->flags = flags; optr->flags = flags;
optr->width = width; optr->width = width;
optr->precision = precision; optr->precision = precision;
@ -562,7 +563,7 @@ static int parsefmt(const char *format,
} }
/* is there a trailing piece */ /* is there a trailing piece */
outlen = fmt - start; outlen = (size_t)(fmt - start);
if(outlen) { if(outlen) {
optr = &out[ocount++]; optr = &out[ocount++];
if(ocount > MAX_SEGMENTS) if(ocount > MAX_SEGMENTS)
@ -688,7 +689,7 @@ static int formatf(
mp_intmax_t signed_num; /* Used to convert negative in positive. */ mp_intmax_t signed_num; /* Used to convert negative in positive. */
char *w; char *w;
size_t outlen = optr->outlen; size_t outlen = optr->outlen;
int flags = optr->flags; unsigned int flags = optr->flags;
if(outlen) { if(outlen) {
char *str = optr->start; char *str = optr->start;
@ -710,7 +711,7 @@ static int formatf(
else else
width = -width; width = -width;
flags |= FLAGS_LEFT; flags |= FLAGS_LEFT;
flags &= ~FLAGS_PAD_NIL; flags &= ~(unsigned int)FLAGS_PAD_NIL;
} }
} }
else else
@ -867,7 +868,7 @@ number:
str = nilstr; str = nilstr;
len = sizeof(nilstr) - 1; len = sizeof(nilstr) - 1;
/* Disable quotes around (nil) */ /* Disable quotes around (nil) */
flags &= (~FLAGS_ALT); flags &= ~(unsigned int)FLAGS_ALT;
} }
else { else {
str = ""; str = "";
@ -886,13 +887,13 @@ number:
if(flags & FLAGS_ALT) if(flags & FLAGS_ALT)
OUTCHAR('"'); OUTCHAR('"');
if(!(flags&FLAGS_LEFT)) if(!(flags & FLAGS_LEFT))
while(width-- > 0) while(width-- > 0)
OUTCHAR(' '); OUTCHAR(' ');
for(; len && *str; len--) for(; len && *str; len--)
OUTCHAR(*str++); OUTCHAR(*str++);
if(flags&FLAGS_LEFT) if(flags & FLAGS_LEFT)
while(width-- > 0) while(width-- > 0)
OUTCHAR(' '); OUTCHAR(' ');
@ -952,12 +953,13 @@ number:
*fptr = 0; *fptr = 0;
if(width >= 0) { if(width >= 0) {
size_t dlen;
if(width >= (int)sizeof(work)) if(width >= (int)sizeof(work))
width = sizeof(work)-1; width = sizeof(work)-1;
/* RECURSIVE USAGE */ /* RECURSIVE USAGE */
len = curl_msnprintf(fptr, left, "%d", width); dlen = (size_t)curl_msnprintf(fptr, left, "%d", width);
fptr += len; fptr += dlen;
left -= len; left -= dlen;
} }
if(prec >= 0) { if(prec >= 0) {
/* for each digit in the integer part, we can have one less /* for each digit in the integer part, we can have one less
@ -965,7 +967,7 @@ number:
size_t maxprec = sizeof(work) - 2; size_t maxprec = sizeof(work) - 2;
double val = iptr->val.dnum; double val = iptr->val.dnum;
if(width > 0 && prec <= width) if(width > 0 && prec <= width)
maxprec -= width; maxprec -= (size_t)width;
while(val >= 10.0) { while(val >= 10.0) {
val /= 10; val /= 10;
maxprec--; maxprec--;
@ -1039,7 +1041,7 @@ static int addbyter(unsigned char outc, void *f)
struct nsprintf *infop = f; struct nsprintf *infop = f;
if(infop->length < infop->max) { if(infop->length < infop->max) {
/* only do this if we haven't reached max length yet */ /* only do this if we haven't reached max length yet */
*infop->buffer++ = outc; /* store */ *infop->buffer++ = (char)outc; /* store */
infop->length++; /* we are now one byte larger */ infop->length++; /* we are now one byte larger */
return 0; /* fputc() returns like this on success */ return 0; /* fputc() returns like this on success */
} }
@ -1139,7 +1141,7 @@ char *curl_maprintf(const char *format, ...)
static int storebuffer(unsigned char outc, void *f) static int storebuffer(unsigned char outc, void *f)
{ {
char **buffer = f; char **buffer = f;
**buffer = outc; **buffer = (char)outc;
(*buffer)++; (*buffer)++;
return 0; return 0;
} }

View File

@ -71,7 +71,7 @@ static const unsigned char tolowermap[256] = {
altered by the current locale. */ altered by the current locale. */
char Curl_raw_toupper(char in) char Curl_raw_toupper(char in)
{ {
return touppermap[(unsigned char) in]; return (char)touppermap[(unsigned char) in];
} }
@ -79,7 +79,7 @@ char Curl_raw_toupper(char in)
altered by the current locale. */ altered by the current locale. */
char Curl_raw_tolower(char in) char Curl_raw_tolower(char in)
{ {
return tolowermap[(unsigned char) in]; return (char)tolowermap[(unsigned char) in];
} }
/* /*