byte_zero is also miscompiled by gcc 4.3.2

master
leitner 16 years ago
parent 4678c3c08e
commit 6d4c89ea72

@ -1,6 +1,7 @@
0.28: 0.28:
add uint64 pack and unpack routines add uint64 pack and unpack routines
fix subtle typo in sub_of (David Sirovsky) fix subtle typo in sub_of (David Sirovsky)
work around gcc bugs
0.27: 0.27:
add fmt_strm add fmt_strm

@ -2,6 +2,14 @@
/* 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
/* gcc 4.3.1 generates wrong code for this, so I'm switching to
* simpler code */
register char* s=out;
size_t i;
for (i=0; i<len; ++i)
s[i]=0;
#else
register char* s=out; register char* s=out;
register const char* t=s+len; register const char* t=s+len;
for (;;) { for (;;) {
@ -10,4 +18,5 @@ void byte_zero(void* out, size_t len) {
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
} }

@ -1,4 +1,5 @@
#include "byte.h" #include "byte.h"
#include <assert.h>
#include "errmsg.h" #include "errmsg.h"
#include <string.h> #include <string.h>
@ -11,26 +12,60 @@ int main() {
// carp("both aligned"); // carp("both aligned");
byte_copy(buf,16,text); byte_copy(buf,16,text);
if (memcmp(buf,"this is a test!\n\0",18)) assert(memcmp(buf,"this is a test!\n\0",18)==0);
die(1,"fail 1");
memset(buf,0,sizeof(buf)); memset(buf,0,sizeof(buf));
// carp("destination aligned, source unaligned"); // carp("destination aligned, source unaligned");
byte_copy(buf,15,text+1); byte_copy(buf,15,text+1);
if (memcmp(buf,"his is a test!\n\0\0",18)) assert(memcmp(buf,"his is a test!\n\0\0",18)==0);
die(1,"fail 2");
memset(buf,0,sizeof(buf)); memset(buf,0,sizeof(buf));
// carp("destination unaligned, source aligned"); // carp("destination unaligned, source aligned");
byte_copy(buf+1,15,text); byte_copy(buf+1,15,text);
if (memcmp(buf,"\0this is a test!\0\0",18)) assert(memcmp(buf,"\0this is a test!\0\0",18)==0);
die(1,"fail 3");
memset(buf,0,sizeof(buf)); memset(buf,0,sizeof(buf));
// carp("both unaligned"); // carp("both unaligned");
byte_copy(buf+1,10,text+3); byte_copy(buf+1,10,text+3);
if (memcmp(buf,"\0s is a tes\0\0",14)) assert(memcmp(buf,"\0s is a tes\0\0",14)==0);
die(1,"fail 4");
memset(buf,0,sizeof(buf));
byte_copyr(buf,16,text);
assert(memcmp(buf,"this is a test!\n\0",18)==0);
memset(buf,0,sizeof(buf));
byte_copyr(buf,15,text+1);
assert(memcmp(buf,"his is a test!\n\0\0",18)==0);
memset(buf,0,sizeof(buf));
byte_copyr(buf+1,15,text);
assert(memcmp(buf,"\0this is a test!\0\0",18)==0);
memset(buf,0,sizeof(buf));
byte_copyr(buf+1,10,text+3);
assert(memcmp(buf,"\0s is a tes\0\0",14)==0);
memset(buf,0,sizeof(buf));
byte_copy(buf,16,text);
byte_copy(buf,16,buf+1);
assert(memcmp(buf,"his is a test!\n\0\0",18)==0);
memset(buf,0,sizeof(buf));
byte_copy(buf,16,text);
byte_copyr(buf+1,16,buf);
assert(memcmp(buf,"tthis is a test!\n",18)==0);
assert(byte_diff(text,15,"this is a test!")==0);
assert(byte_diff(text,16,"this is a test!")>0);
assert(byte_diff("this is a test!",16,text)<0);
assert(byte_chr("0123456789abcdef",17,'9')==9);
assert(byte_rchr("0123456789abcdef",17,'9')==9);
assert(byte_chr("0123456789abcdef",17,'A')==17);
assert(byte_rchr("0123456789abcdef",17,'A')==17);
byte_zero(buf,16);
assert(byte_equal(buf,16,"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"));
return 0; return 0;
} }

Loading…
Cancel
Save