get rid of -Wconversion warnings

master
leitner 11 years ago
parent e1081e4b13
commit d14d2536f0

@ -4,7 +4,7 @@ size_t scan_8int(const char* src,unsigned int* dest) {
register const char *tmp=src;
register unsigned int l=0;
register unsigned char c;
while ((c=(char)(*tmp-'0'))<8) {
while ((c=(unsigned char)(*tmp-'0'))<8) {
if (l>>(sizeof(l)*8-3)) break;
l=l*8+c;
++tmp;

@ -4,11 +4,11 @@ size_t scan_8longlong(const char *src,unsigned long long *dest) {
register const char *tmp=src;
register unsigned long long l=0;
register unsigned char c;
while ((c=*tmp-'0')<8) {
while ((c=(unsigned char)(*tmp-'0'))<8) {
if (l>>(sizeof(l)*8-3)) break;
l=l*8+c;
++tmp;
}
*dest=l;
return tmp-src;
return (size_t)(tmp-src);
}

@ -4,11 +4,11 @@ size_t scan_8longn(const char *src,size_t n,unsigned long *dest) {
register const char *tmp=src;
register unsigned long l=0;
register unsigned char c;
while (n-->0 && (c=*tmp-'0')<8) {
while (n-->0 && (c=(unsigned char)(*tmp-'0'))<8) {
if (l>>(sizeof(l)*8-3)) break;
l=l*8+c;
++tmp;
}
*dest=l;
return tmp-src;
return (size_t)(tmp-src);
}

@ -11,5 +11,5 @@ size_t scan_charsetnskip(const char *s,const char *charset,size_t limit) {
if (*i!=*t) break;
++t;
}
return t-s;
return (size_t)(t-s);
}

@ -1,10 +1,10 @@
#include "scan.h"
int scan_fromhex(unsigned char c) {
c-='0';
c=(unsigned char)(c-'0');
if (c<=9) return c;
c&=~0x20;
c-='A'-'0';
c=(unsigned char)(c&~0x20);
c=(unsigned char)(c-('A'-'0'));
if (c<6) return c+10;
return -1;
/* more readable but creates worse code:

@ -12,11 +12,11 @@ extern char** environ;
static int parsetime(const char*c,struct tm* x) {
unsigned long tmp;
c+=scan_ulong(c,&tmp); x->tm_hour=tmp;
c+=scan_ulong(c,&tmp); x->tm_hour=(int)tmp;
if (*c!=':') return -1; ++c;
c+=scan_ulong(c,&tmp); x->tm_min=tmp;
c+=scan_ulong(c,&tmp); x->tm_min=(int)tmp;
if (*c!=':') return -1; ++c;
c+=scan_ulong(c,&tmp); x->tm_sec=tmp;
c+=scan_ulong(c,&tmp); x->tm_sec=(int)tmp;
if (*c!=' ') return -1;
return 0;
}
@ -37,14 +37,14 @@ size_t scan_httpdate(const char *in,time_t *t) {
}
}
c+=4; if (*c==' ') ++c;
c+=scan_ulong(c,&tmp); x.tm_mday=tmp;
c+=scan_ulong(c,&tmp); x.tm_mday=(int)tmp;
++c;
if (parsetime(c,&x)) return 0;
c+=9;
c+=scan_ulong(c,&tmp); x.tm_year=tmp-1900;
c+=scan_ulong(c,&tmp); x.tm_year=(int)(tmp-1900);
goto done;
}
c+=scan_ulong(c,&tmp); x.tm_mday=tmp;
c+=scan_ulong(c,&tmp); x.tm_mday=(int)tmp;
while (*c==' ') ++c; // work around crappy sqlite download httpd
// ++c;
for (i=0; i<12; ++i)
@ -53,9 +53,9 @@ size_t scan_httpdate(const char *in,time_t *t) {
}
c+=4;
c+=scan_ulong(c,&tmp);
if (tmp>1000) x.tm_year=tmp-1900; else
if (tmp<70) x.tm_year=tmp+100; else
x.tm_year=tmp;
if (tmp>1000) x.tm_year=(int)(tmp-1900); else
if (tmp<70) x.tm_year=(int)(tmp+100); else
x.tm_year=(int)tmp;
++c;
if (parsetime(c,&x)) return 0;
c+=9;
@ -86,5 +86,5 @@ done:
#endif
}
#endif
return c-in;
return (size_t)(c-in);
}

@ -1,5 +1,5 @@
#include "scan.h"
size_t scan_long(const char *src,long *dest) {
return scan_longn(src,-1,dest);
return scan_longn(src,(size_t)(-1),dest);
}

@ -3,17 +3,17 @@
static const unsigned long maxlong = ((unsigned long)-1)>>1;
size_t scan_longlong(const char* src,signed long long* dest) {
unsigned int i,o;
size_t i,o;
unsigned long long l;
char c=src[0];
int neg=c=='-';
unsigned int neg=c=='-';
o=c=='-' || c=='+';
if ((i=scan_ulonglong(src+o,&l))) {
if (i>0 && l>maxlong+neg) {
l/=10;
--i;
}
if (i+o) *dest=c=='-'?-l:l;
if (i+o) *dest=(signed long long)(c=='-'?-l:l);
return i+o;
} return 0;
}

@ -9,7 +9,7 @@ size_t scan_longn(const char *src,size_t n,long *dest) {
unsigned int neg;
int ok;
if (!n--) return 0;
tmp=src; l=0; ok=neg=0;
tmp=src; l=0; ok=0; neg=0;
switch (*tmp) {
case '-': neg=1;
case '+': ++tmp;

@ -11,5 +11,5 @@ size_t scan_noncharsetnskip(const char *s,const char *charset,size_t limit) {
if (*i==*t) break;
++t;
}
return t-s;
return (size_t)(t-s);
}

@ -1,6 +1,6 @@
#include "scan.h"
static const unsigned int maxshort = ((unsigned short)-1)>>1;
static const unsigned short maxshort = ((unsigned short)-1)>>1;
size_t scan_short(const char* src,short* dest) {
register const char *tmp;
@ -14,7 +14,7 @@ size_t scan_short(const char* src,short* dest) {
case '+': ++tmp;
}
while ((c=(unsigned char)(*tmp-'0'))<10) {
unsigned long int n;
unsigned short int n;
/* we want to do: l=l*10+c
* but we need to check for integer overflow.
* to check whether l*10 overflows, we could do
@ -22,17 +22,17 @@ size_t scan_short(const char* src,short* dest) {
* however, multiplication and division are expensive.
* so instead of *10 we do (l<<3) (i.e. *8) + (l<<1) (i.e. *2)
* and check for overflow on all the intermediate steps */
n=(unsigned int)l<<3; if ((n>>3)!=(unsigned int)l) break;
n=(unsigned short)(l<<3); if ((n>>3)!=(unsigned short)l) break;
if (n+(l<<1) < n) break;
n+=l<<1;
n=(unsigned short)(n+(l<<1));
if (n+c < n) break;
n+=c;
n=(unsigned short)(n+c);
if (n > maxshort+neg) break;
l=n;
l=(short)n;
++tmp;
ok=1;
}
if (!ok) return 0;
*dest=(neg?-l:l);
*dest=(short)(neg?-l:l);
return (size_t)(tmp-src);
}

@ -14,7 +14,7 @@ size_t scan_uint(const char* src,unsigned int* dest) {
register const char *tmp=src;
register unsigned int l=0;
register unsigned char c;
while ((c=(char)(*tmp-'0'))<10) {
while ((c=(unsigned char)(*tmp-'0'))<10) {
unsigned int n;
/* division is very slow on most architectures */
n=l<<3; if ((n>>3)!=l) break;

@ -4,7 +4,7 @@ size_t scan_ulonglong(const char *src,unsigned long long *dest) {
register const char *tmp=src;
register unsigned long long l=0;
register unsigned char c;
while ((c=(char)(*tmp-'0'))<10) {
while ((c=(unsigned char)(*tmp-'0'))<10) {
unsigned long long n;
/* division is very slow on most architectures */
n=l<<3; if ((n>>3)!=l) break;

@ -4,7 +4,7 @@ size_t scan_ulongn(const char* src,size_t n,unsigned long int* dest) {
register const char *tmp=src;
register unsigned long int l=0;
register unsigned char c;
while (n-->0 && (c=(char)(*tmp-'0'))<10) {
while (n-->0 && (c=(unsigned char)(*tmp-'0'))<10) {
unsigned long int n;
/* we want to do: l=l*10+c
* but we need to check for integer overflow.

@ -14,17 +14,17 @@ size_t scan_ushort(const char* src,unsigned short* dest) {
register const char *tmp=src;
register unsigned short int l=0;
register unsigned char c;
while ((c=*tmp-'0')<10) {
while ((c=(unsigned char)(*tmp-'0'))<10) {
unsigned short int n;
/* division is very slow on most architectures */
n=l<<3; if ((n>>3)!=l) break;
n=(unsigned short)(l<<3); if ((n>>3)!=l) break;
if (n+(l<<1) < n) break;
n+=l<<1;
n=(unsigned short)(n+(l<<1));
if ((unsigned short)(n+c) < n) break;
l=n+c;
l=(unsigned short)(n+c);
++tmp;
}
if (tmp-src) *dest=l;
return tmp-src;
return (size_t)(tmp-src);
}
}

@ -5,5 +5,5 @@ size_t scan_whitenskip(const char *s,size_t limit) {
register const char *t=s;
register const char *u=t+limit;
while (t<u && isspace(*t)) ++t;
return t-s;
return (size_t)(t-s);
}

@ -4,10 +4,10 @@ size_t scan_xint(const char* src,unsigned int* dest) {
register const char *tmp=src;
register unsigned int l=0;
register unsigned char c;
while ((l>>(sizeof(l)*8-4))==0 && (c=scan_fromhex(*tmp))<16) {
while ((l>>(sizeof(l)*8-4))==0 && (c=(unsigned char)scan_fromhex((unsigned char)*tmp))<16) {
l=(l<<4)+c;
++tmp;
}
*dest=l;
return tmp-src;
return (size_t)(tmp-src);
}

@ -2,12 +2,12 @@
size_t scan_xlonglong(const char* src,unsigned long long* dest) {
register const char *tmp=src;
register long long l=0;
register unsigned long long l=0;
register unsigned char c;
while ((l>>(sizeof(l)*8-4))==0 && (c=scan_fromhex(*tmp))<16) {
while ((l>>(sizeof(l)*8-4))==0 && (c=(unsigned char)scan_fromhex((unsigned char)*tmp))<16) {
l=(l<<4)+c;
++tmp;
}
*dest=l;
return tmp-src;
return (size_t)(tmp-src);
}

@ -4,10 +4,10 @@ size_t scan_xlongn(const char *src,size_t n,unsigned long *dest) {
register const char *tmp=src;
register unsigned long l=0;
register unsigned char c;
while (n-->0 && (l>>(sizeof(l)*8-4))==0 && (c=scan_fromhex(*tmp))<16) {
while (n-->0 && (l>>(sizeof(l)*8-4))==0 && (c=(unsigned char)scan_fromhex((unsigned char)*tmp))<16) {
l=(l<<4)+c;
++tmp;
}
*dest=l;
return tmp-src;
return (size_t)(tmp-src);
}

@ -4,10 +4,10 @@ size_t scan_xshort(const char* src,unsigned short* dest) {
register const char *tmp=src;
register unsigned short l=0;
register unsigned char c;
while ((l>>(sizeof(l)*8-4))==0 && (c=scan_fromhex(*tmp))<16) {
l=(l<<4)+c;
while ((l>>(sizeof(l)*8-4))==0 && (c=(unsigned char)scan_fromhex((unsigned char)*tmp))<16) {
l=(unsigned short)((l<<4)+c);
++tmp;
}
*dest=l;
return tmp-src;
return (size_t)(tmp-src);
}

@ -9,5 +9,5 @@ size_t str_chr(const char *in, char needle) {
if (!*t || *t==c) break; ++t;
if (!*t || *t==c) break; ++t;
}
return t-in;
return (size_t)(t-in);
}

@ -9,5 +9,5 @@ size_t str_copy(char *out,const char *in) {
if (!(*s=*t)) break; ++s; ++t;
if (!(*s=*t)) break; ++s; ++t;
}
return s-out;
return (size_t)(s-out);
}

@ -9,5 +9,5 @@ size_t str_len(const char* in) {
if (!*t) break; ++t;
if (!*t) break; ++t;
}
return t-in;
return (size_t)(t-in);
}

@ -10,5 +10,5 @@ size_t str_rchr(const char *in, char needle) {
if (!*t) break; if (*t==c) found=t; ++t;
if (!*t) break; if (*t==c) found=t; ++t;
}
return (found?found:t)-in;
return (size_t)((found?found:t)-in);
}

Loading…
Cancel
Save