From e1081e4b13d632bb1ab978bed154c51ab40a7c20 Mon Sep 17 00:00:00 2001 From: leitner Date: Fri, 14 Mar 2014 01:53:08 +0000 Subject: [PATCH] remove -Wconversion warnings --- scan/scan_8int.c | 4 ++-- scan/scan_8long.c | 2 +- scan/scan_8short.c | 6 +++--- scan/scan_asn1derlength.c | 2 +- scan/scan_int.c | 12 ++++++------ scan/scan_longn.c | 8 ++++---- scan/scan_nonwhitenskip.c | 2 +- scan/scan_uint.c | 4 ++-- scan/scan_ulonglong.c | 4 ++-- scan/scan_ulongn.c | 4 ++-- scan/scan_utf8.c | 4 ++-- test/marshal.c | 21 ++++++++++++++++++++- 12 files changed, 46 insertions(+), 27 deletions(-) diff --git a/scan/scan_8int.c b/scan/scan_8int.c index 868faa0..5a6fcaa 100644 --- a/scan/scan_8int.c +++ b/scan/scan_8int.c @@ -4,11 +4,11 @@ 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=*tmp-'0')<8) { + while ((c=(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); } diff --git a/scan/scan_8long.c b/scan/scan_8long.c index 72078b2..06283cc 100644 --- a/scan/scan_8long.c +++ b/scan/scan_8long.c @@ -1,5 +1,5 @@ #include "scan.h" size_t scan_8long(const char *src,unsigned long *dest) { - return scan_8longn(src,-1,dest); + return scan_8longn(src,(size_t)-1,dest); } diff --git a/scan/scan_8short.c b/scan/scan_8short.c index b83837d..c723b2b 100644 --- a/scan/scan_8short.c +++ b/scan/scan_8short.c @@ -4,11 +4,11 @@ size_t scan_8short(const char* src,unsigned short* dest) { register const char *tmp=src; register unsigned short 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; + l=(unsigned short)(l*8+c); ++tmp; } *dest=l; - return tmp-src; + return (size_t)(tmp-src); } diff --git a/scan/scan_asn1derlength.c b/scan/scan_asn1derlength.c index e546cd0..dfb22f0 100644 --- a/scan/scan_asn1derlength.c +++ b/scan/scan_asn1derlength.c @@ -21,5 +21,5 @@ size_t scan_asn1derlength(const char* src,size_t len,unsigned long long* length) src++; if (src+*length>max) return 0; /* catch integer overflow */ if ((uintptr_t)src+*length<(uintptr_t)src) return 0; /* gcc 4.1 removes this check without the cast to uintptr_t */ - return src-orig; + return (size_t)(src-orig); } diff --git a/scan/scan_int.c b/scan/scan_int.c index 4f82f0b..f314a17 100644 --- a/scan/scan_int.c +++ b/scan/scan_int.c @@ -6,15 +6,15 @@ size_t scan_int(const char* src,int* dest) { register const char *tmp; register int l; register unsigned char c; - int neg; + unsigned int neg; int ok; - tmp=src; l=0; ok=neg=0; + tmp=src; l=0; ok=0; neg=0; switch (*tmp) { case '-': neg=1; case '+': ++tmp; } while ((c=(unsigned char)(*tmp-'0'))<10) { - unsigned long int n; + unsigned 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 @@ -23,12 +23,12 @@ size_t scan_int(const char* src,int* dest) { * 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; - if (n+(l<<1) < n) break; - n+=l<<1; + if (n+((unsigned int)l<<1) < n) break; + n+=(unsigned int)l<<1; if (n+c < n) break; n+=c; if (n > maxint+neg) break; - l=n; + l=(int)n; ++tmp; ok=1; } diff --git a/scan/scan_longn.c b/scan/scan_longn.c index f1c0a92..a632904 100644 --- a/scan/scan_longn.c +++ b/scan/scan_longn.c @@ -6,7 +6,7 @@ size_t scan_longn(const char *src,size_t n,long *dest) { register const char *tmp; register long int l; register unsigned char c; - int neg; + unsigned int neg; int ok; if (!n--) return 0; tmp=src; l=0; ok=neg=0; @@ -24,12 +24,12 @@ size_t scan_longn(const char *src,size_t n,long *dest) { * 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 long)l<<3; if ((n>>3)!=(unsigned long)l) break; - if (n+(l<<1) < n) break; - n+=l<<1; + if (n+((unsigned long)l<<1) < n) break; + n+=(unsigned long)l<<1; if (n+c < n) break; n+=c; if (n > maxlong+neg) break; - l=n; + l=(long)n; ++tmp; ok=1; } diff --git a/scan/scan_nonwhitenskip.c b/scan/scan_nonwhitenskip.c index 541b2e4..2771069 100644 --- a/scan/scan_nonwhitenskip.c +++ b/scan/scan_nonwhitenskip.c @@ -5,5 +5,5 @@ size_t scan_nonwhitenskip(const char *s,size_t limit) { register const char *t=s; register const char *u=t+limit; while (t>3)!=l) break; @@ -25,6 +25,6 @@ size_t scan_uint(const char* src,unsigned int* dest) { ++tmp; } if (tmp-src) *dest=l; - return tmp-src; + return (size_t)(tmp-src); } } diff --git a/scan/scan_ulonglong.c b/scan/scan_ulonglong.c index 27e2634..71c69c6 100644 --- a/scan/scan_ulonglong.c +++ b/scan/scan_ulonglong.c @@ -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=*tmp-'0')<10) { + while ((c=(char)(*tmp-'0'))<10) { unsigned long long n; /* division is very slow on most architectures */ n=l<<3; if ((n>>3)!=l) break; @@ -15,5 +15,5 @@ size_t scan_ulonglong(const char *src,unsigned long long *dest) { ++tmp; } if (tmp-src) *dest=l; - return tmp-src; + return (size_t)(tmp-src); } diff --git a/scan/scan_ulongn.c b/scan/scan_ulongn.c index f611299..f685114 100644 --- a/scan/scan_ulongn.c +++ b/scan/scan_ulongn.c @@ -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=*tmp-'0')<10) { + while (n-->0 && (c=(char)(*tmp-'0'))<10) { unsigned long int n; /* we want to do: l=l*10+c * but we need to check for integer overflow. @@ -21,5 +21,5 @@ size_t scan_ulongn(const char* src,size_t n,unsigned long int* dest) { ++tmp; } if (tmp-src) *dest=l; - return tmp-src; + return (size_t)(tmp-src); } diff --git a/scan/scan_utf8.c b/scan/scan_utf8.c index a0d68aa..f668e0b 100644 --- a/scan/scan_utf8.c +++ b/scan/scan_utf8.c @@ -39,7 +39,7 @@ size_t scan_utf8(const char* in,size_t len,uint32_t* num) { * expression can be written as * 1 << (k*5-4+(k==2)) */ - m=(1<<(k*5-4+(k==2))); + m=((uint32_t)1<<(k*5-4+(k==2))); while (k>1) { if ((*in&0xc0)!=0x80) return 0; i=(i<<6) | ((*in++)&0x3f); @@ -47,6 +47,6 @@ size_t scan_utf8(const char* in,size_t len,uint32_t* num) { } if (i