get rid of -Wconversion warnings
This commit is contained in:
parent
e1081e4b13
commit
d14d2536f0
@ -4,7 +4,7 @@ size_t scan_8int(const char* src,unsigned int* dest) {
|
|||||||
register const char *tmp=src;
|
register const char *tmp=src;
|
||||||
register unsigned int l=0;
|
register unsigned int l=0;
|
||||||
register unsigned char c;
|
register unsigned char c;
|
||||||
while ((c=(char)(*tmp-'0'))<8) {
|
while ((c=(unsigned char)(*tmp-'0'))<8) {
|
||||||
if (l>>(sizeof(l)*8-3)) break;
|
if (l>>(sizeof(l)*8-3)) break;
|
||||||
l=l*8+c;
|
l=l*8+c;
|
||||||
++tmp;
|
++tmp;
|
||||||
|
@ -4,11 +4,11 @@ size_t scan_8longlong(const char *src,unsigned long long *dest) {
|
|||||||
register const char *tmp=src;
|
register const char *tmp=src;
|
||||||
register unsigned long long l=0;
|
register unsigned long long l=0;
|
||||||
register unsigned char c;
|
register unsigned char c;
|
||||||
while ((c=*tmp-'0')<8) {
|
while ((c=(unsigned char)(*tmp-'0'))<8) {
|
||||||
if (l>>(sizeof(l)*8-3)) break;
|
if (l>>(sizeof(l)*8-3)) break;
|
||||||
l=l*8+c;
|
l=l*8+c;
|
||||||
++tmp;
|
++tmp;
|
||||||
}
|
}
|
||||||
*dest=l;
|
*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 const char *tmp=src;
|
||||||
register unsigned long l=0;
|
register unsigned long l=0;
|
||||||
register unsigned char c;
|
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;
|
if (l>>(sizeof(l)*8-3)) break;
|
||||||
l=l*8+c;
|
l=l*8+c;
|
||||||
++tmp;
|
++tmp;
|
||||||
}
|
}
|
||||||
*dest=l;
|
*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;
|
if (*i!=*t) break;
|
||||||
++t;
|
++t;
|
||||||
}
|
}
|
||||||
return t-s;
|
return (size_t)(t-s);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include "scan.h"
|
#include "scan.h"
|
||||||
|
|
||||||
int scan_fromhex(unsigned char c) {
|
int scan_fromhex(unsigned char c) {
|
||||||
c-='0';
|
c=(unsigned char)(c-'0');
|
||||||
if (c<=9) return c;
|
if (c<=9) return c;
|
||||||
c&=~0x20;
|
c=(unsigned char)(c&~0x20);
|
||||||
c-='A'-'0';
|
c=(unsigned char)(c-('A'-'0'));
|
||||||
if (c<6) return c+10;
|
if (c<6) return c+10;
|
||||||
return -1;
|
return -1;
|
||||||
/* more readable but creates worse code:
|
/* more readable but creates worse code:
|
||||||
|
@ -12,11 +12,11 @@ extern char** environ;
|
|||||||
|
|
||||||
static int parsetime(const char*c,struct tm* x) {
|
static int parsetime(const char*c,struct tm* x) {
|
||||||
unsigned long tmp;
|
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;
|
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;
|
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;
|
if (*c!=' ') return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -37,14 +37,14 @@ size_t scan_httpdate(const char *in,time_t *t) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
c+=4; if (*c==' ') ++c;
|
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;
|
++c;
|
||||||
if (parsetime(c,&x)) return 0;
|
if (parsetime(c,&x)) return 0;
|
||||||
c+=9;
|
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;
|
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
|
while (*c==' ') ++c; // work around crappy sqlite download httpd
|
||||||
// ++c;
|
// ++c;
|
||||||
for (i=0; i<12; ++i)
|
for (i=0; i<12; ++i)
|
||||||
@ -53,9 +53,9 @@ size_t scan_httpdate(const char *in,time_t *t) {
|
|||||||
}
|
}
|
||||||
c+=4;
|
c+=4;
|
||||||
c+=scan_ulong(c,&tmp);
|
c+=scan_ulong(c,&tmp);
|
||||||
if (tmp>1000) x.tm_year=tmp-1900; else
|
if (tmp>1000) x.tm_year=(int)(tmp-1900); else
|
||||||
if (tmp<70) x.tm_year=tmp+100; else
|
if (tmp<70) x.tm_year=(int)(tmp+100); else
|
||||||
x.tm_year=tmp;
|
x.tm_year=(int)tmp;
|
||||||
++c;
|
++c;
|
||||||
if (parsetime(c,&x)) return 0;
|
if (parsetime(c,&x)) return 0;
|
||||||
c+=9;
|
c+=9;
|
||||||
@ -86,5 +86,5 @@ done:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return c-in;
|
return (size_t)(c-in);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "scan.h"
|
#include "scan.h"
|
||||||
|
|
||||||
size_t scan_long(const char *src,long *dest) {
|
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;
|
static const unsigned long maxlong = ((unsigned long)-1)>>1;
|
||||||
|
|
||||||
size_t scan_longlong(const char* src,signed long long* dest) {
|
size_t scan_longlong(const char* src,signed long long* dest) {
|
||||||
unsigned int i,o;
|
size_t i,o;
|
||||||
unsigned long long l;
|
unsigned long long l;
|
||||||
char c=src[0];
|
char c=src[0];
|
||||||
int neg=c=='-';
|
unsigned int neg=c=='-';
|
||||||
o=c=='-' || c=='+';
|
o=c=='-' || c=='+';
|
||||||
if ((i=scan_ulonglong(src+o,&l))) {
|
if ((i=scan_ulonglong(src+o,&l))) {
|
||||||
if (i>0 && l>maxlong+neg) {
|
if (i>0 && l>maxlong+neg) {
|
||||||
l/=10;
|
l/=10;
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
if (i+o) *dest=c=='-'?-l:l;
|
if (i+o) *dest=(signed long long)(c=='-'?-l:l);
|
||||||
return i+o;
|
return i+o;
|
||||||
} return 0;
|
} return 0;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ size_t scan_longn(const char *src,size_t n,long *dest) {
|
|||||||
unsigned int neg;
|
unsigned int neg;
|
||||||
int ok;
|
int ok;
|
||||||
if (!n--) return 0;
|
if (!n--) return 0;
|
||||||
tmp=src; l=0; ok=neg=0;
|
tmp=src; l=0; ok=0; neg=0;
|
||||||
switch (*tmp) {
|
switch (*tmp) {
|
||||||
case '-': neg=1;
|
case '-': neg=1;
|
||||||
case '+': ++tmp;
|
case '+': ++tmp;
|
||||||
|
@ -11,5 +11,5 @@ size_t scan_noncharsetnskip(const char *s,const char *charset,size_t limit) {
|
|||||||
if (*i==*t) break;
|
if (*i==*t) break;
|
||||||
++t;
|
++t;
|
||||||
}
|
}
|
||||||
return t-s;
|
return (size_t)(t-s);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "scan.h"
|
#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) {
|
size_t scan_short(const char* src,short* dest) {
|
||||||
register const char *tmp;
|
register const char *tmp;
|
||||||
@ -14,7 +14,7 @@ size_t scan_short(const char* src,short* dest) {
|
|||||||
case '+': ++tmp;
|
case '+': ++tmp;
|
||||||
}
|
}
|
||||||
while ((c=(unsigned char)(*tmp-'0'))<10) {
|
while ((c=(unsigned char)(*tmp-'0'))<10) {
|
||||||
unsigned long int n;
|
unsigned short int n;
|
||||||
/* we want to do: l=l*10+c
|
/* we want to do: l=l*10+c
|
||||||
* but we need to check for integer overflow.
|
* but we need to check for integer overflow.
|
||||||
* to check whether l*10 overflows, we could do
|
* 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.
|
* however, multiplication and division are expensive.
|
||||||
* so instead of *10 we do (l<<3) (i.e. *8) + (l<<1) (i.e. *2)
|
* 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 */
|
* 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;
|
if (n+(l<<1) < n) break;
|
||||||
n+=l<<1;
|
n=(unsigned short)(n+(l<<1));
|
||||||
if (n+c < n) break;
|
if (n+c < n) break;
|
||||||
n+=c;
|
n=(unsigned short)(n+c);
|
||||||
if (n > maxshort+neg) break;
|
if (n > maxshort+neg) break;
|
||||||
l=n;
|
l=(short)n;
|
||||||
++tmp;
|
++tmp;
|
||||||
ok=1;
|
ok=1;
|
||||||
}
|
}
|
||||||
if (!ok) return 0;
|
if (!ok) return 0;
|
||||||
*dest=(neg?-l:l);
|
*dest=(short)(neg?-l:l);
|
||||||
return (size_t)(tmp-src);
|
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 const char *tmp=src;
|
||||||
register unsigned int l=0;
|
register unsigned int l=0;
|
||||||
register unsigned char c;
|
register unsigned char c;
|
||||||
while ((c=(char)(*tmp-'0'))<10) {
|
while ((c=(unsigned char)(*tmp-'0'))<10) {
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
/* division is very slow on most architectures */
|
/* division is very slow on most architectures */
|
||||||
n=l<<3; if ((n>>3)!=l) break;
|
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 const char *tmp=src;
|
||||||
register unsigned long long l=0;
|
register unsigned long long l=0;
|
||||||
register unsigned char c;
|
register unsigned char c;
|
||||||
while ((c=(char)(*tmp-'0'))<10) {
|
while ((c=(unsigned char)(*tmp-'0'))<10) {
|
||||||
unsigned long long n;
|
unsigned long long n;
|
||||||
/* division is very slow on most architectures */
|
/* division is very slow on most architectures */
|
||||||
n=l<<3; if ((n>>3)!=l) break;
|
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 const char *tmp=src;
|
||||||
register unsigned long int l=0;
|
register unsigned long int l=0;
|
||||||
register unsigned char c;
|
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;
|
unsigned long int n;
|
||||||
/* we want to do: l=l*10+c
|
/* we want to do: l=l*10+c
|
||||||
* but we need to check for integer overflow.
|
* 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 const char *tmp=src;
|
||||||
register unsigned short int l=0;
|
register unsigned short int l=0;
|
||||||
register unsigned char c;
|
register unsigned char c;
|
||||||
while ((c=*tmp-'0')<10) {
|
while ((c=(unsigned char)(*tmp-'0'))<10) {
|
||||||
unsigned short int n;
|
unsigned short int n;
|
||||||
/* division is very slow on most architectures */
|
/* 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;
|
if (n+(l<<1) < n) break;
|
||||||
n+=l<<1;
|
n=(unsigned short)(n+(l<<1));
|
||||||
if ((unsigned short)(n+c) < n) break;
|
if ((unsigned short)(n+c) < n) break;
|
||||||
l=n+c;
|
l=(unsigned short)(n+c);
|
||||||
++tmp;
|
++tmp;
|
||||||
}
|
}
|
||||||
if (tmp-src) *dest=l;
|
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 *t=s;
|
||||||
register const char *u=t+limit;
|
register const char *u=t+limit;
|
||||||
while (t<u && isspace(*t)) ++t;
|
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 const char *tmp=src;
|
||||||
register unsigned int l=0;
|
register unsigned int l=0;
|
||||||
register unsigned char c;
|
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;
|
l=(l<<4)+c;
|
||||||
++tmp;
|
++tmp;
|
||||||
}
|
}
|
||||||
*dest=l;
|
*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) {
|
size_t scan_xlonglong(const char* src,unsigned long long* dest) {
|
||||||
register const char *tmp=src;
|
register const char *tmp=src;
|
||||||
register long long l=0;
|
register unsigned long long l=0;
|
||||||
register unsigned char c;
|
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;
|
l=(l<<4)+c;
|
||||||
++tmp;
|
++tmp;
|
||||||
}
|
}
|
||||||
*dest=l;
|
*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 const char *tmp=src;
|
||||||
register unsigned long l=0;
|
register unsigned long l=0;
|
||||||
register unsigned char c;
|
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;
|
l=(l<<4)+c;
|
||||||
++tmp;
|
++tmp;
|
||||||
}
|
}
|
||||||
*dest=l;
|
*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 const char *tmp=src;
|
||||||
register unsigned short l=0;
|
register unsigned short l=0;
|
||||||
register unsigned char c;
|
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;
|
l=(unsigned short)((l<<4)+c);
|
||||||
++tmp;
|
++tmp;
|
||||||
}
|
}
|
||||||
*dest=l;
|
*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;
|
||||||
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;
|
||||||
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;
|
||||||
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;
|
||||||
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…
x
Reference in New Issue
Block a user