Browse Source

shut up new gcc 6 warnings

master
Felix von Leitner 6 years ago
parent
commit
9e3ba6e772
  1. 12
      byte/byte_chr.c
  2. 32
      byte/byte_copy.c
  3. 12
      byte/byte_copyr.c
  4. 17
      byte/byte_zero.c
  5. 15
      dns/dns_packet.c
  6. 19
      fmt/fmt_str.c
  7. 4
      fmt/fmt_varint.c
  8. 6
      scan/scan_httpdate.c
  9. 25
      scan/scan_iso8601.c
  10. 3
      socket/scan_ip4.c
  11. 12
      str/str_chr.c
  12. 12
      str/str_copy.c
  13. 12
      str/str_diff.c
  14. 12
      str/str_diffn.c
  15. 12
      str/str_len.c
  16. 19
      str/str_rchr.c
  17. 16
      str/str_start.c
  18. 3
      stralloc/stralloc_diff.c
  19. 3
      stralloc/stralloc_diffs.c
  20. 3
      textcode/fmt_ldapescape.c
  21. 3
      textcode/fmt_ldapescape2.c
  22. 3
      textcode/fmt_quotedprintable.c
  23. 3
      textcode/fmt_urlencoded.c
  24. 6
      textcode/fmt_uuencoded.c
  25. 15
      textcode/fmt_yenc.c
  26. 3
      textcode/scan_uuencoded.c

12
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);
}

32
byte/byte_copy.c

@ -1,36 +1,12 @@
#include <stdint.h>
#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; i<len; ++i)
s[i]=t[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
d[i]=s[i];
}

12
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;
}
}

17
byte/byte_zero.c

@ -1,22 +1,15 @@
#include "byte.h"
#include <string.h>
/* 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; ++i)
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
}

15
dns/dns_packet.c

@ -43,24 +43,29 @@ unsigned int dns_packet_getname(const char *buf,unsigned int len,unsigned int po
unsigned int namelen = 0;
for (;;) {
if (pos >= 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;
}

19
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);
}

4
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;
}

6
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;

25
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;

3
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;
}

12
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);
}

12
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);
}

12
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;
}

12
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;
}

12
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);
}

19
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);
}

16
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;
}

3
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;

3
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;

3
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;

3
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;

3
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;

3
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;

6
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;
}

15
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;
}

3
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;

Loading…
Cancel
Save