From d26b8082d8d6610c4103da9cb8823dbb62ad77a0 Mon Sep 17 00:00:00 2001 From: leitner Date: Wed, 27 Apr 2016 14:07:49 +0000 Subject: [PATCH] shut up new gcc 6 warnings --- byte/byte_chr.c | 12 ++++++++---- byte/byte_copy.c | 32 ++++---------------------------- byte/byte_copyr.c | 12 ++++++++---- byte/byte_zero.c | 17 +++++------------ dns/dns_packet.c | 15 ++++++++++----- fmt/fmt_str.c | 19 +++++++++++++++---- fmt/fmt_varint.c | 4 ++++ scan/scan_httpdate.c | 6 ++++-- scan/scan_iso8601.c | 25 ++++++++++++++++++------- socket/scan_ip4.c | 3 ++- str/str_chr.c | 12 ++++++++---- str/str_copy.c | 12 ++++++++---- str/str_diff.c | 12 ++++++++---- str/str_diffn.c | 12 ++++++++---- str/str_len.c | 12 ++++++++---- str/str_rchr.c | 19 +++++++++++++++---- str/str_start.c | 16 ++++++++++++---- stralloc/stralloc_diff.c | 3 ++- stralloc/stralloc_diffs.c | 3 ++- textcode/fmt_ldapescape.c | 3 ++- textcode/fmt_ldapescape2.c | 3 ++- textcode/fmt_quotedprintable.c | 3 ++- textcode/fmt_urlencoded.c | 3 ++- textcode/fmt_uuencoded.c | 6 ++++-- textcode/fmt_yenc.c | 15 ++++++++++----- textcode/scan_uuencoded.c | 3 ++- 26 files changed, 173 insertions(+), 109 deletions(-) diff --git a/byte/byte_chr.c b/byte/byte_chr.c index a5dc988..6185966 100644 --- a/byte/byte_chr.c +++ b/byte/byte_chr.c @@ -7,10 +7,14 @@ size_t byte_chr(const void* haystack, size_t len, char needle) { register const char* s=haystack; register const char* t=s+len; for (;;) { - if (s==t) break; if (*s==c) break; ++s; - if (s==t) break; if (*s==c) break; ++s; - if (s==t) break; if (*s==c) break; ++s; - if (s==t) break; if (*s==c) break; ++s; + if (s==t || *s==c) break; + ++s; + if (s==t || *s==c) break; + ++s; + if (s==t || *s==c) break; + ++s; + if (s==t || *s==c) break; + ++s; } return (size_t)(s-(const char*)haystack); } diff --git a/byte/byte_copy.c b/byte/byte_copy.c index d85431e..a087127 100644 --- a/byte/byte_copy.c +++ b/byte/byte_copy.c @@ -1,36 +1,12 @@ +#include #include "byte.h" /* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1] * to out[len-1]. */ void byte_copy(void* out, size_t len, const void* in) { - char* s=out; - const char* t=in; -#if 1 - /* gcc 4.3.1 generates wrong code for this, so I'm switching to - * simpler code */ + char* d=out; + const char* s=in; size_t i; for (i=0; i127) { - while ((unsigned long)s&(sizeof(unsigned long)-1)) { - *s=*t; ++s; ++t; - } - /* s (destination) is now unsigned long aligned */ -#ifndef __i386__ - if (!((unsigned long)t&(sizeof(unsigned long)-1))) -#endif - while (t+sizeof(unsigned long)<=u) { - *(unsigned long*)s=*(unsigned long*)t; - s+=sizeof(unsigned long); t+=sizeof(unsigned long); - } - } - for (;;) { - if (t==u) break; *s=*t; ++s; ++t; - if (t==u) break; *s=*t; ++s; ++t; - if (t==u) break; *s=*t; ++s; ++t; - if (t==u) break; *s=*t; ++s; ++t; - } -#endif + d[i]=s[i]; } diff --git a/byte/byte_copyr.c b/byte/byte_copyr.c index 018d5c6..4a24a3a 100644 --- a/byte/byte_copyr.c +++ b/byte/byte_copyr.c @@ -7,9 +7,13 @@ void byte_copyr(void* out, size_t len, const void* in) { register const char* t=in; register const char* u=t+len; for (;;) { - if (t>=u) break; --u; --s; *s=*u; - if (t>=u) break; --u; --s; *s=*u; - if (t>=u) break; --u; --s; *s=*u; - if (t>=u) break; --u; --s; *s=*u; + if (t>=u) break; + --u; --s; *s=*u; + if (t>=u) break; + --u; --s; *s=*u; + if (t>=u) break; + --u; --s; *s=*u; + if (t>=u) break; + --u; --s; *s=*u; } } diff --git a/byte/byte_zero.c b/byte/byte_zero.c index faf7864..35ae780 100644 --- a/byte/byte_zero.c +++ b/byte/byte_zero.c @@ -1,22 +1,15 @@ #include "byte.h" +#include /* byte_zero sets the bytes out[0], out[1], ..., out[len-1] to 0 */ void byte_zero(void* out, size_t len) { -#if 1 - /* gcc 4.3.1 generates wrong code for this, so I'm switching to - * simpler code */ + /* instead of doing this ourselves, defer to the hopefully amazingly + * optimized memset from libc */ + memset(out,0,len); +#if 0 register char* s=out; size_t i; for (i=0; i= len) goto PROTO; ch = buf[pos++]; + if (pos >= len) goto PROTO; + ch = buf[pos++]; if (++loop >= 1000) goto PROTO; if (state) { - if (namelen + 1 > sizeof name) goto PROTO; name[namelen++] = ch; + if (namelen + 1 > sizeof name) goto PROTO; + name[namelen++] = ch; --state; } else { while (ch >= 192) { where = ch; where -= 192; where <<= 8; - if (pos >= len) goto PROTO; ch = buf[pos++]; + if (pos >= len) goto PROTO; + ch = buf[pos++]; if (!firstcompress) firstcompress = pos; pos = where + ch; - if (pos >= len) goto PROTO; ch = buf[pos++]; + if (pos >= len) goto PROTO; + ch = buf[pos++]; if (++loop >= 1000) goto PROTO; } if (ch >= 64) goto PROTO; - if (namelen + 1 > sizeof name) goto PROTO; name[namelen++] = ch; + if (namelen + 1 > sizeof name) goto PROTO; + name[namelen++] = ch; if (!ch) break; state = ch; } diff --git a/fmt/fmt_str.c b/fmt/fmt_str.c index 7bafc8e..e81c77e 100644 --- a/fmt/fmt_str.c +++ b/fmt/fmt_str.c @@ -4,10 +4,21 @@ size_t fmt_str(char *out,const char *in) { register char* s=out; register const char* t=in; for (;;) { - if (!*t) break; if (s) { *s=*t; ++s; } ++t; - if (!*t) break; if (s) { *s=*t; ++s; } ++t; - if (!*t) break; if (s) { *s=*t; ++s; } ++t; - if (!*t) break; if (s) { *s=*t; ++s; } ++t; + if (!*t) break; + if (s) { *s=*t; ++s; } + ++t; + + if (!*t) break; + if (s) { *s=*t; ++s; } + ++t; + + if (!*t) break; + if (s) { *s=*t; ++s; } + ++t; + + if (!*t) break; + if (s) { *s=*t; ++s; } + ++t; } return (size_t)(t-in); } diff --git a/fmt/fmt_varint.c b/fmt/fmt_varint.c index ae64b29..a5b726d 100644 --- a/fmt/fmt_varint.c +++ b/fmt/fmt_varint.c @@ -8,6 +8,10 @@ size_t fmt_varint(char* dest,unsigned long long l) { for (i=0; l; ++i, l>>=7) { if (dest) dest[i]=(l&0x7f) | ((!!(l&~0x7f))<<7); } + if (!i) { /* l was 0 */ + if (dest) dest[0]=0; + ++i; + } return i; } diff --git a/scan/scan_httpdate.c b/scan/scan_httpdate.c index 710db0d..ec8773f 100644 --- a/scan/scan_httpdate.c +++ b/scan/scan_httpdate.c @@ -13,9 +13,11 @@ extern char** environ; static int parsetime(const char*c,struct tm* x) { unsigned long 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=(int)tmp; - if (*c!=':') return -1; ++c; + if (*c!=':') return -1; + ++c; c+=scan_ulong(c,&tmp); x->tm_sec=(int)tmp; if (*c!=' ') return -1; return 0; diff --git a/scan/scan_iso8601.c b/scan/scan_iso8601.c index 917a7dc..1033f7d 100644 --- a/scan/scan_iso8601.c +++ b/scan/scan_iso8601.c @@ -17,12 +17,18 @@ size_t scan_iso8601(const char* in,struct timespec* t) { unsigned long tmp; size_t i; if (!(c=in)) return 0; - if ((i=scan_ulong(c,&tmp))<4 || c[i]!='-') return 0; c+=i+1; x.tm_year=(int)(tmp-1900); - if (scan_ulong(c,&tmp)!=2 || c[2]!='-') return 0; c+=3; x.tm_mon=(int)(tmp-1); - if (scan_ulong(c,&tmp)!=2 || c[2]!='T') return 0; c+=3; x.tm_mday=(int)tmp; - if (scan_ulong(c,&tmp)!=2 || c[2]!=':') return 0; c+=3; x.tm_hour=(int)tmp; - if (scan_ulong(c,&tmp)!=2 || c[2]!=':') return 0; c+=3; x.tm_min=(int)tmp; - if (scan_ulong(c,&tmp)!=2) return 0; c+=2; x.tm_sec=(int)tmp; + if ((i=scan_ulong(c,&tmp))<4 || c[i]!='-') return 0; + c+=i+1; x.tm_year=(int)(tmp-1900); + if (scan_ulong(c,&tmp)!=2 || c[2]!='-') return 0; + c+=3; x.tm_mon=(int)(tmp-1); + if (scan_ulong(c,&tmp)!=2 || c[2]!='T') return 0; + c+=3; x.tm_mday=(int)tmp; + if (scan_ulong(c,&tmp)!=2 || c[2]!=':') return 0; + c+=3; x.tm_hour=(int)tmp; + if (scan_ulong(c,&tmp)!=2 || c[2]!=':') return 0; + c+=3; x.tm_min=(int)tmp; + if (scan_ulong(c,&tmp)!=2) return 0; + c+=2; x.tm_sec=(int)tmp; if (*c=='.') { ++c; i=scan_ulong(c,&tmp); @@ -38,7 +44,11 @@ size_t scan_iso8601(const char* in,struct timespec* t) { } } +#ifdef __MINGW32__ + x.tm_wday=x.tm_yday=x.tm_isdst=0; +#else x.tm_wday=x.tm_yday=x.tm_isdst=x.tm_gmtoff=0; +#endif #if defined(__dietlibc__) || defined(__GLIBC__) t->tv_sec=timegm(&x); #elif defined(__MINGW32__) @@ -63,7 +73,8 @@ size_t scan_iso8601(const char* in,struct timespec* t) { if (*c=='+' || *c=='-') { int signum = (*c=='-') - (*c=='+'); ++c; - if (scan_ulong(c,&tmp)!=4) return 0; c+=4; + if (scan_ulong(c,&tmp)!=4) return 0; + c+=4; t->tv_sec+=signum*60*(int)(tmp/100)*60+(int)(tmp%100); } else if (*c=='Z') ++c; diff --git a/socket/scan_ip4.c b/socket/scan_ip4.c index 44502f1..0256070 100644 --- a/socket/scan_ip4.c +++ b/socket/scan_ip4.c @@ -12,7 +12,8 @@ size_t scan_ip4(const char *s,char ip[4]) len+=(j=scan_ulong(s,&u))+1; if (!j || u>255) return 0; ip[i]=(char)u; s+=j; - if (i<3 && *s!='.') return 0; ++s; + if (i<3 && *s!='.') return 0; + ++s; } return len-1; } diff --git a/str/str_chr.c b/str/str_chr.c index 3938e79..37d24fe 100644 --- a/str/str_chr.c +++ b/str/str_chr.c @@ -4,10 +4,14 @@ size_t str_chr(const char *in, char needle) { register const char* t=in; register const char c=needle; for (;;) { - if (!*t || *t==c) break; ++t; - if (!*t || *t==c) break; ++t; - if (!*t || *t==c) break; ++t; - if (!*t || *t==c) break; ++t; + 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 (size_t)(t-in); } diff --git a/str/str_copy.c b/str/str_copy.c index 0a61cea..9bca180 100644 --- a/str/str_copy.c +++ b/str/str_copy.c @@ -4,10 +4,14 @@ size_t str_copy(char *out,const char *in) { register char* s=out; register const char* t=in; for (;;) { - if (!(*s=*t)) break; ++s; ++t; - if (!(*s=*t)) break; ++s; ++t; - if (!(*s=*t)) break; ++s; ++t; - if (!(*s=*t)) break; ++s; ++t; + 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 (size_t)(s-out); } diff --git a/str/str_diff.c b/str/str_diff.c index 2d1cb6c..57ff0b3 100644 --- a/str/str_diff.c +++ b/str/str_diff.c @@ -10,10 +10,14 @@ int str_diff(const char* a, const char* b) { register const unsigned char* t=(const unsigned char*)b; register int j; for (;;) { - if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; - if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; - if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; - if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; + if ((j=(*s-*t)) || !*t) break; + ++s; ++t; + if ((j=(*s-*t)) || !*t) break; + ++s; ++t; + if ((j=(*s-*t)) || !*t) break; + ++s; ++t; + if ((j=(*s-*t)) || !*t) break; + ++s; ++t; } return j; } diff --git a/str/str_diffn.c b/str/str_diffn.c index e7dd98c..055d432 100644 --- a/str/str_diffn.c +++ b/str/str_diffn.c @@ -12,10 +12,14 @@ int str_diffn(const char* a, const char* b, size_t limit) { register int j; j=0; for (;;) { - if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; - if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; - if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; - if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; + if (t>=u || (j=(*s-*t)) || !*t) break; + ++s; ++t; + if (t>=u || (j=(*s-*t)) || !*t) break; + ++s; ++t; + if (t>=u || (j=(*s-*t)) || !*t) break; + ++s; ++t; + if (t>=u || (j=(*s-*t)) || !*t) break; + ++s; ++t; } return j; } diff --git a/str/str_len.c b/str/str_len.c index 64a3c4d..2fe759e 100644 --- a/str/str_len.c +++ b/str/str_len.c @@ -4,10 +4,14 @@ size_t str_len(const char* in) { register const char* t=in; for (;;) { - if (!*t) break; ++t; - if (!*t) break; ++t; - if (!*t) break; ++t; - if (!*t) break; ++t; + if (!*t) break; + ++t; + if (!*t) break; + ++t; + if (!*t) break; + ++t; + if (!*t) break; + ++t; } return (size_t)(t-in); } diff --git a/str/str_rchr.c b/str/str_rchr.c index a0aebf9..595001a 100644 --- a/str/str_rchr.c +++ b/str/str_rchr.c @@ -5,10 +5,21 @@ size_t str_rchr(const char *in, char needle) { register const char c=needle; register const char* found=0; for (;;) { - 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; + 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 (size_t)((found?found:t)-in); } diff --git a/str/str_start.c b/str/str_start.c index 54e039e..5cff770 100644 --- a/str/str_start.c +++ b/str/str_start.c @@ -5,10 +5,18 @@ int str_start(const char* a, const char* b) { register const char* s=a; register const char* t=b; for (;;) { - if (!*t) return 1; if (*s!=*t) break; ++s; ++t; - if (!*t) return 1; if (*s!=*t) break; ++s; ++t; - if (!*t) return 1; if (*s!=*t) break; ++s; ++t; - if (!*t) return 1; if (*s!=*t) break; ++s; ++t; + if (!*t) return 1; + if (*s!=*t) break; + ++s; ++t; + if (!*t) return 1; + if (*s!=*t) break; + ++s; ++t; + if (!*t) return 1; + if (*s!=*t) break; + ++s; ++t; + if (!*t) return 1; + if (*s!=*t) break; + ++s; ++t; } return 0; } diff --git a/stralloc/stralloc_diff.c b/stralloc/stralloc_diff.c index fe3fda9..a222c05 100644 --- a/stralloc/stralloc_diff.c +++ b/stralloc/stralloc_diff.c @@ -6,7 +6,8 @@ extern int stralloc_diff(const stralloc* a,const stralloc* b) { register size_t i; register int j; for (i=0;;++i) { - if (i==a->len) return i==b->len?0:-1; if (i==b->len) return 1; + if (i==a->len) return i==b->len?0:-1; + if (i==b->len) return 1; if ((j=((unsigned char)(a->s[i])-(unsigned char)(b->s[i])))) return j; } return j; diff --git a/stralloc/stralloc_diffs.c b/stralloc/stralloc_diffs.c index 06d7d44..ce4a007 100644 --- a/stralloc/stralloc_diffs.c +++ b/stralloc/stralloc_diffs.c @@ -6,7 +6,8 @@ extern int stralloc_diffs(const stralloc* a,const char* b) { register size_t i; register int j; for (i=0;;++i) { - if (i==a->len) return (!b[i])?0:-1; if (!b[i]) return 1; + if (i==a->len) return (!b[i])?0:-1; + if (!b[i]) return 1; if ((j=((unsigned char)(a->s[i])-(unsigned char)(b[i])))) return j; } return j; diff --git a/textcode/fmt_ldapescape.c b/textcode/fmt_ldapescape.c index 82820cd..bee8988 100644 --- a/textcode/fmt_ldapescape.c +++ b/textcode/fmt_ldapescape.c @@ -16,7 +16,8 @@ size_t fmt_ldapescape(char* dest,const char* src,size_t len) { } written+=3; } else { - if (dest) dest[written]=s[i]; ++written; + if (dest) dest[written]=s[i]; + ++written; } /* in case someone gives us malicious input */ if (written>((size_t)-1)/2) return (size_t)-1; diff --git a/textcode/fmt_ldapescape2.c b/textcode/fmt_ldapescape2.c index c951258..dfb8373 100644 --- a/textcode/fmt_ldapescape2.c +++ b/textcode/fmt_ldapescape2.c @@ -15,7 +15,8 @@ size_t fmt_ldapescape2(char* dest,const char* src,size_t len,const char* escapem } written+=3; } else { - if (dest) dest[written]=s[i]; ++written; + if (dest) dest[written]=s[i]; + ++written; } /* in case someone gives us malicious input */ if (written>((size_t)-1)/2) return (size_t)-1; diff --git a/textcode/fmt_quotedprintable.c b/textcode/fmt_quotedprintable.c index 781c255..a0e26b9 100644 --- a/textcode/fmt_quotedprintable.c +++ b/textcode/fmt_quotedprintable.c @@ -15,7 +15,8 @@ size_t fmt_quotedprintable2(char* dest,const char* src,size_t len,const char* es } written+=3; } else { - if (dest) dest[written]=s[i]; ++written; + if (dest) dest[written]=s[i]; + ++written; } /* in case someone gives us malicious input */ if (written>((size_t)-1)/2) return (size_t)-1; diff --git a/textcode/fmt_urlencoded.c b/textcode/fmt_urlencoded.c index 5f42c77..ba624ea 100644 --- a/textcode/fmt_urlencoded.c +++ b/textcode/fmt_urlencoded.c @@ -23,7 +23,8 @@ size_t fmt_urlencoded2(char* dest,const char* src,size_t len,const char* escapem } written+=3; } else { - if (dest) dest[written]=s[i]; ++written; + if (dest) dest[written]=s[i]; + ++written; } /* in case someone gives us malicious input */ if (written>((size_t)-1)/2) return (size_t)-1; diff --git a/textcode/fmt_uuencoded.c b/textcode/fmt_uuencoded.c index abf83f8..65876b4 100644 --- a/textcode/fmt_uuencoded.c +++ b/textcode/fmt_uuencoded.c @@ -16,7 +16,8 @@ size_t fmt_uuencoded(char* dest,const char* src,size_t len) { { register unsigned int diff; if (len>45) { i=15; diff=45; } else { i=(len+2)/3; diff=len; } - if (orig) *dest=enc(diff); ++dest; + if (orig) *dest=enc(diff); + ++dest; len-=diff; } for (; i; --i) { @@ -31,7 +32,8 @@ size_t fmt_uuencoded(char* dest,const char* src,size_t len) { } dest+=4; s+=3; } - if (orig) *dest='\n'; ++dest; + if (orig) *dest='\n'; + ++dest; } return dest-orig; } diff --git a/textcode/fmt_yenc.c b/textcode/fmt_yenc.c index d77a2f8..95eb708 100644 --- a/textcode/fmt_yenc.c +++ b/textcode/fmt_yenc.c @@ -10,7 +10,8 @@ size_t fmt_yenc(char* dest,const char* src,size_t len) { switch (c) { case ' ': /* escape space at line ending */ if (linelen==253) { - if (dest) dest[written]='\n'; ++written; linelen=0; + if (dest) dest[written]='\n'; + ++written; linelen=0; } goto dontescape; case 'F': /* escape "^From " */ @@ -22,22 +23,26 @@ size_t fmt_yenc(char* dest,const char* src,size_t len) { case '\n': case '\r': case '=': - if (dest) dest[written]='='; ++written; + if (dest) dest[written]='='; + ++written; c+=64; /* fall through */ default: dontescape: ++linelen; - if (dest) dest[written]=c; ++written; + if (dest) dest[written]=c; + ++written; if (linelen>253) { - if (dest) dest[written]='\n'; ++written; linelen=0; + if (dest) dest[written]='\n'; + ++written; linelen=0; } } /* in case someone gives us malicious input */ if (written>((size_t)-1)/2) return (size_t)-1; } if (linelen) { - if (dest) dest[written]='\n'; ++written; + if (dest) dest[written]='\n'; + ++written; } return written; } diff --git a/textcode/scan_uuencoded.c b/textcode/scan_uuencoded.c index 326ef76..1a2af7a 100644 --- a/textcode/scan_uuencoded.c +++ b/textcode/scan_uuencoded.c @@ -5,7 +5,8 @@ size_t scan_uuencoded(const char *src,char *dest,size_t *destlen) { size_t tmp; register const unsigned char* s=(const unsigned char*) src; const char* orig=dest; - if ((len=*s-' ')>64) return 0; len&=63; + if ((len=*s-' ')>64) return 0; + len&=63; ++s; while (len>0) { if (s[0]-' '>64 || s[1]-' '>64 || s[2]-' '>64 || s[3]-' '>64) return 0;