shut up new gcc 6 warnings

master
leitner 9 years ago
parent 05e4dcc94a
commit d26b8082d8

@ -7,10 +7,14 @@ size_t byte_chr(const void* haystack, size_t len, char needle) {
register const char* s=haystack; register const char* s=haystack;
register const char* t=s+len; register const char* t=s+len;
for (;;) { for (;;) {
if (s==t) break; if (*s==c) break; ++s; if (s==t || *s==c) break;
if (s==t) break; if (*s==c) break; ++s; ++s;
if (s==t) break; if (*s==c) break; ++s; if (s==t || *s==c) break;
if (s==t) break; if (*s==c) break; ++s; ++s;
if (s==t || *s==c) break;
++s;
if (s==t || *s==c) break;
++s;
} }
return (size_t)(s-(const char*)haystack); return (size_t)(s-(const char*)haystack);
} }

@ -1,36 +1,12 @@
#include <stdint.h>
#include "byte.h" #include "byte.h"
/* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1] /* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1]
* to out[len-1]. */ * to out[len-1]. */
void byte_copy(void* out, size_t len, const void* in) { void byte_copy(void* out, size_t len, const void* in) {
char* s=out; char* d=out;
const char* t=in; const char* s=in;
#if 1
/* gcc 4.3.1 generates wrong code for this, so I'm switching to
* simpler code */
size_t i; size_t i;
for (i=0; i<len; ++i) for (i=0; i<len; ++i)
s[i]=t[i]; d[i]=s[i];
#else
const char* u=t+len;
if (len>127) {
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
} }

@ -7,9 +7,13 @@ void byte_copyr(void* out, size_t len, const void* in) {
register const char* t=in; register const char* t=in;
register const char* u=t+len; register const char* u=t+len;
for (;;) { for (;;) {
if (t>=u) break; --u; --s; *s=*u; if (t>=u) break;
if (t>=u) break; --u; --s; *s=*u; --u; --s; *s=*u;
if (t>=u) break; --u; --s; *s=*u; if (t>=u) break;
if (t>=u) break; --u; --s; *s=*u; --u; --s; *s=*u;
if (t>=u) break;
--u; --s; *s=*u;
if (t>=u) break;
--u; --s; *s=*u;
} }
} }

@ -1,22 +1,15 @@
#include "byte.h" #include "byte.h"
#include <string.h>
/* byte_zero sets the bytes out[0], out[1], ..., out[len-1] to 0 */ /* byte_zero sets the bytes out[0], out[1], ..., out[len-1] to 0 */
void byte_zero(void* out, size_t len) { void byte_zero(void* out, size_t len) {
#if 1 /* instead of doing this ourselves, defer to the hopefully amazingly
/* gcc 4.3.1 generates wrong code for this, so I'm switching to * optimized memset from libc */
* simpler code */ memset(out,0,len);
#if 0
register char* s=out; register char* s=out;
size_t i; size_t i;
for (i=0; i<len; ++i) for (i=0; i<len; ++i)
s[i]=0; s[i]=0;
#else
register char* s=out;
register const char* t=s+len;
for (;;) {
if (s==t) break; *s=0; ++s;
if (s==t) break; *s=0; ++s;
if (s==t) break; *s=0; ++s;
if (s==t) break; *s=0; ++s;
}
#endif #endif
} }

@ -43,24 +43,29 @@ unsigned int dns_packet_getname(const char *buf,unsigned int len,unsigned int po
unsigned int namelen = 0; unsigned int namelen = 0;
for (;;) { for (;;) {
if (pos >= len) goto PROTO; ch = buf[pos++]; if (pos >= len) goto PROTO;
ch = buf[pos++];
if (++loop >= 1000) goto PROTO; if (++loop >= 1000) goto PROTO;
if (state) { if (state) {
if (namelen + 1 > sizeof name) goto PROTO; name[namelen++] = ch; if (namelen + 1 > sizeof name) goto PROTO;
name[namelen++] = ch;
--state; --state;
} }
else { else {
while (ch >= 192) { while (ch >= 192) {
where = ch; where -= 192; where <<= 8; 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; if (!firstcompress) firstcompress = pos;
pos = where + ch; 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 (++loop >= 1000) goto PROTO;
} }
if (ch >= 64) 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; if (!ch) break;
state = ch; state = ch;
} }

@ -4,10 +4,21 @@ size_t fmt_str(char *out,const char *in) {
register char* s=out; register char* s=out;
register const char* t=in; register const char* t=in;
for (;;) { for (;;) {
if (!*t) break; if (s) { *s=*t; ++s; } ++t; if (!*t) break;
if (!*t) break; if (s) { *s=*t; ++s; } ++t; if (s) { *s=*t; ++s; }
if (!*t) break; if (s) { *s=*t; ++s; } ++t; ++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); return (size_t)(t-in);
} }

@ -8,6 +8,10 @@ size_t fmt_varint(char* dest,unsigned long long l) {
for (i=0; l; ++i, l>>=7) { for (i=0; l; ++i, l>>=7) {
if (dest) dest[i]=(l&0x7f) | ((!!(l&~0x7f))<<7); if (dest) dest[i]=(l&0x7f) | ((!!(l&~0x7f))<<7);
} }
if (!i) { /* l was 0 */
if (dest) dest[0]=0;
++i;
}
return i; return i;
} }

@ -13,9 +13,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=(int)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; 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; c+=scan_ulong(c,&tmp); x->tm_sec=(int)tmp;
if (*c!=' ') return -1; if (*c!=' ') return -1;
return 0; return 0;

@ -17,12 +17,18 @@ size_t scan_iso8601(const char* in,struct timespec* t) {
unsigned long tmp; unsigned long tmp;
size_t i; size_t i;
if (!(c=in)) return 0; 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 ((i=scan_ulong(c,&tmp))<4 || c[i]!='-') return 0;
if (scan_ulong(c,&tmp)!=2 || c[2]!='-') return 0; c+=3; x.tm_mon=(int)(tmp-1); c+=i+1; x.tm_year=(int)(tmp-1900);
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;
if (scan_ulong(c,&tmp)!=2 || c[2]!=':') return 0; c+=3; x.tm_hour=(int)tmp; c+=3; x.tm_mon=(int)(tmp-1);
if (scan_ulong(c,&tmp)!=2 || c[2]!=':') return 0; c+=3; x.tm_min=(int)tmp; if (scan_ulong(c,&tmp)!=2 || c[2]!='T') return 0;
if (scan_ulong(c,&tmp)!=2) return 0; c+=2; x.tm_sec=(int)tmp; 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=='.') { if (*c=='.') {
++c; ++c;
i=scan_ulong(c,&tmp); 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; x.tm_wday=x.tm_yday=x.tm_isdst=x.tm_gmtoff=0;
#endif
#if defined(__dietlibc__) || defined(__GLIBC__) #if defined(__dietlibc__) || defined(__GLIBC__)
t->tv_sec=timegm(&x); t->tv_sec=timegm(&x);
#elif defined(__MINGW32__) #elif defined(__MINGW32__)
@ -63,7 +73,8 @@ size_t scan_iso8601(const char* in,struct timespec* t) {
if (*c=='+' || *c=='-') { if (*c=='+' || *c=='-') {
int signum = (*c=='-') - (*c=='+'); int signum = (*c=='-') - (*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); t->tv_sec+=signum*60*(int)(tmp/100)*60+(int)(tmp%100);
} else if (*c=='Z') } else if (*c=='Z')
++c; ++c;

@ -12,7 +12,8 @@ size_t scan_ip4(const char *s,char ip[4])
len+=(j=scan_ulong(s,&u))+1; len+=(j=scan_ulong(s,&u))+1;
if (!j || u>255) return 0; if (!j || u>255) return 0;
ip[i]=(char)u; s+=j; ip[i]=(char)u; s+=j;
if (i<3 && *s!='.') return 0; ++s; if (i<3 && *s!='.') return 0;
++s;
} }
return len-1; return len-1;
} }

@ -4,10 +4,14 @@ size_t str_chr(const char *in, char needle) {
register const char* t=in; register const char* t=in;
register const char c=needle; register const char c=needle;
for (;;) { for (;;) {
if (!*t || *t==c) break; ++t; if (!*t || *t==c) break;
if (!*t || *t==c) break; ++t; ++t;
if (!*t || *t==c) break; ++t; if (!*t || *t==c) break;
if (!*t || *t==c) break; ++t; ++t;
if (!*t || *t==c) break;
++t;
if (!*t || *t==c) break;
++t;
} }
return (size_t)(t-in); return (size_t)(t-in);
} }

@ -4,10 +4,14 @@ size_t str_copy(char *out,const char *in) {
register char* s=out; register char* s=out;
register const char* t=in; register const char* t=in;
for (;;) { for (;;) {
if (!(*s=*t)) break; ++s; ++t; if (!(*s=*t)) break;
if (!(*s=*t)) break; ++s; ++t; ++s; ++t;
if (!(*s=*t)) break; ++s; ++t; if (!(*s=*t)) break;
if (!(*s=*t)) break; ++s; ++t; ++s; ++t;
if (!(*s=*t)) break;
++s; ++t;
if (!(*s=*t)) break;
++s; ++t;
} }
return (size_t)(s-out); return (size_t)(s-out);
} }

@ -10,10 +10,14 @@ int str_diff(const char* a, const char* b) {
register const unsigned char* t=(const unsigned char*)b; register const unsigned char* t=(const unsigned char*)b;
register int j; register int j;
for (;;) { for (;;) {
if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; if ((j=(*s-*t)) || !*t) break;
if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; ++s; ++t;
if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; if ((j=(*s-*t)) || !*t) break;
if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; ++s; ++t;
if ((j=(*s-*t)) || !*t) break;
++s; ++t;
if ((j=(*s-*t)) || !*t) break;
++s; ++t;
} }
return j; return j;
} }

@ -12,10 +12,14 @@ int str_diffn(const char* a, const char* b, size_t limit) {
register int j; register int j;
j=0; j=0;
for (;;) { for (;;) {
if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; if (t>=u || (j=(*s-*t)) || !*t) break;
if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; ++s; ++t;
if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; if (t>=u || (j=(*s-*t)) || !*t) break;
if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t; ++s; ++t;
if (t>=u || (j=(*s-*t)) || !*t) break;
++s; ++t;
if (t>=u || (j=(*s-*t)) || !*t) break;
++s; ++t;
} }
return j; return j;
} }

@ -4,10 +4,14 @@
size_t str_len(const char* in) { size_t str_len(const char* in) {
register const char* t=in; register const char* t=in;
for (;;) { for (;;) {
if (!*t) break; ++t; if (!*t) break;
if (!*t) break; ++t; ++t;
if (!*t) break; ++t; if (!*t) break;
if (!*t) break; ++t; ++t;
if (!*t) break;
++t;
if (!*t) break;
++t;
} }
return (size_t)(t-in); return (size_t)(t-in);
} }

@ -5,10 +5,21 @@ size_t str_rchr(const char *in, char needle) {
register const char c=needle; register const char c=needle;
register const char* found=0; register const char* found=0;
for (;;) { for (;;) {
if (!*t) break; if (*t==c) found=t; ++t; if (!*t) break;
if (!*t) break; if (*t==c) found=t; ++t; if (*t==c) found=t;
if (!*t) break; if (*t==c) found=t; ++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); return (size_t)((found?found:t)-in);
} }

@ -5,10 +5,18 @@ int str_start(const char* a, const char* b) {
register const char* s=a; register const char* s=a;
register const char* t=b; register const char* t=b;
for (;;) { for (;;) {
if (!*t) return 1; if (*s!=*t) break; ++s; ++t; if (!*t) return 1;
if (!*t) return 1; if (*s!=*t) break; ++s; ++t; if (*s!=*t) break;
if (!*t) return 1; if (*s!=*t) break; ++s; ++t; ++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; return 0;
} }

@ -6,7 +6,8 @@ extern int stralloc_diff(const stralloc* a,const stralloc* b) {
register size_t i; register size_t i;
register int j; register int j;
for (i=0;;++i) { 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; if ((j=((unsigned char)(a->s[i])-(unsigned char)(b->s[i])))) return j;
} }
return j; return j;

@ -6,7 +6,8 @@ extern int stralloc_diffs(const stralloc* a,const char* b) {
register size_t i; register size_t i;
register int j; register int j;
for (i=0;;++i) { 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; if ((j=((unsigned char)(a->s[i])-(unsigned char)(b[i])))) return j;
} }
return j; return j;

@ -16,7 +16,8 @@ size_t fmt_ldapescape(char* dest,const char* src,size_t len) {
} }
written+=3; written+=3;
} else { } else {
if (dest) dest[written]=s[i]; ++written; if (dest) dest[written]=s[i];
++written;
} }
/* in case someone gives us malicious input */ /* in case someone gives us malicious input */
if (written>((size_t)-1)/2) return (size_t)-1; if (written>((size_t)-1)/2) return (size_t)-1;

@ -15,7 +15,8 @@ size_t fmt_ldapescape2(char* dest,const char* src,size_t len,const char* escapem
} }
written+=3; written+=3;
} else { } else {
if (dest) dest[written]=s[i]; ++written; if (dest) dest[written]=s[i];
++written;
} }
/* in case someone gives us malicious input */ /* in case someone gives us malicious input */
if (written>((size_t)-1)/2) return (size_t)-1; if (written>((size_t)-1)/2) return (size_t)-1;

@ -15,7 +15,8 @@ size_t fmt_quotedprintable2(char* dest,const char* src,size_t len,const char* es
} }
written+=3; written+=3;
} else { } else {
if (dest) dest[written]=s[i]; ++written; if (dest) dest[written]=s[i];
++written;
} }
/* in case someone gives us malicious input */ /* in case someone gives us malicious input */
if (written>((size_t)-1)/2) return (size_t)-1; if (written>((size_t)-1)/2) return (size_t)-1;

@ -23,7 +23,8 @@ size_t fmt_urlencoded2(char* dest,const char* src,size_t len,const char* escapem
} }
written+=3; written+=3;
} else { } else {
if (dest) dest[written]=s[i]; ++written; if (dest) dest[written]=s[i];
++written;
} }
/* in case someone gives us malicious input */ /* in case someone gives us malicious input */
if (written>((size_t)-1)/2) return (size_t)-1; if (written>((size_t)-1)/2) return (size_t)-1;

@ -16,7 +16,8 @@ size_t fmt_uuencoded(char* dest,const char* src,size_t len) {
{ {
register unsigned int diff; register unsigned int diff;
if (len>45) { i=15; diff=45; } else { i=(len+2)/3; diff=len; } 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; len-=diff;
} }
for (; i; --i) { for (; i; --i) {
@ -31,7 +32,8 @@ size_t fmt_uuencoded(char* dest,const char* src,size_t len) {
} }
dest+=4; s+=3; dest+=4; s+=3;
} }
if (orig) *dest='\n'; ++dest; if (orig) *dest='\n';
++dest;
} }
return dest-orig; return dest-orig;
} }

@ -10,7 +10,8 @@ size_t fmt_yenc(char* dest,const char* src,size_t len) {
switch (c) { switch (c) {
case ' ': /* escape space at line ending */ case ' ': /* escape space at line ending */
if (linelen==253) { if (linelen==253) {
if (dest) dest[written]='\n'; ++written; linelen=0; if (dest) dest[written]='\n';
++written; linelen=0;
} }
goto dontescape; goto dontescape;
case 'F': /* escape "^From " */ case 'F': /* escape "^From " */
@ -22,22 +23,26 @@ size_t fmt_yenc(char* dest,const char* src,size_t len) {
case '\n': case '\n':
case '\r': case '\r':
case '=': case '=':
if (dest) dest[written]='='; ++written; if (dest) dest[written]='=';
++written;
c+=64; c+=64;
/* fall through */ /* fall through */
default: default:
dontescape: dontescape:
++linelen; ++linelen;
if (dest) dest[written]=c; ++written; if (dest) dest[written]=c;
++written;
if (linelen>253) { 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 */ /* in case someone gives us malicious input */
if (written>((size_t)-1)/2) return (size_t)-1; if (written>((size_t)-1)/2) return (size_t)-1;
} }
if (linelen) { if (linelen) {
if (dest) dest[written]='\n'; ++written; if (dest) dest[written]='\n';
++written;
} }
return written; return written;
} }

@ -5,7 +5,8 @@ size_t scan_uuencoded(const char *src,char *dest,size_t *destlen) {
size_t tmp; size_t tmp;
register const unsigned char* s=(const unsigned char*) src; register const unsigned char* s=(const unsigned char*) src;
const char* orig=dest; const char* orig=dest;
if ((len=*s-' ')>64) return 0; len&=63; if ((len=*s-' ')>64) return 0;
len&=63;
++s; ++s;
while (len>0) { while (len>0) {
if (s[0]-' '>64 || s[1]-' '>64 || s[2]-' '>64 || s[3]-' '>64) return 0; if (s[0]-' '>64 || s[1]-' '>64 || s[2]-' '>64 || s[3]-' '>64) return 0;

Loading…
Cancel
Save