From f52aa874416bbad56c5808ae03cd00a96212dbbf Mon Sep 17 00:00:00 2001 From: leitner Date: Tue, 6 Jan 2004 23:35:06 +0000 Subject: [PATCH] more alloca fixes --- CHANGES | 1 + GNUmakefile | 2 +- array/array_cat.c | 2 +- havealloca.h | 3 +++ io/iob_send.c | 2 +- mult/imult16.c | 5 +++-- mult/imult32.c | 5 +++-- mult/imult64.c | 5 +++-- socket/scan_ip6if.c | 4 +--- test/b64decode.c | 1 + test/b64encode.c | 1 + test/cescape.c | 2 +- test/unurl.c | 1 + test/urlencode.c | 1 + textcode/scan_tofrom_array.c | 2 +- 15 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 havealloca.h diff --git a/CHANGES b/CHANGES index 10e3ed1..f3e85ae 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,7 @@ head -1 -> head -n 1 apending 0 bytes to an empty array would fail it remove socket_sendfile now that we have io_sendfile + break out alloca #include dependency into havealloca.h 0.16: add buffer_fromsa (make buffer from stralloc) diff --git a/GNUmakefile b/GNUmakefile index bae0830..928301f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -141,7 +141,7 @@ libepoll havesigio.h havebsdsf.h havescope.h havedevpoll.h Makefile dep INCLUDES=buffer.h byte.h fmt.h ip4.h ip6.h mmap.h scan.h socket.h str.h stralloc.h \ uint16.h uint32.h uint64.h open.h textcode.h tai.h taia.h dns.h iopause.h case.h \ -openreadclose.h readclose.h ndelay.h array.h io.h safemult.h iob.h havealloca.h +openreadclose.h readclose.h ndelay.h array.h io.h safemult.h iob.h install: libowfat.a install -d $(INCLUDEDIR) $(MAN3DIR) $(LIBDIR) diff --git a/array/array_cat.c b/array/array_cat.c index 70ee771..80bc6bc 100644 --- a/array/array_cat.c +++ b/array/array_cat.c @@ -6,5 +6,5 @@ void array_cat(array* to,const array* const from) { array_fail(to); return; } - return array_catb(to,from->p,from->initialized); + array_catb(to,from->p,from->initialized); } diff --git a/havealloca.h b/havealloca.h new file mode 100644 index 0000000..365ca67 --- /dev/null +++ b/havealloca.h @@ -0,0 +1,3 @@ +#if defined(__linux__) || defined(_SGI_SOURCE) +#include +#endif diff --git a/io/iob_send.c b/io/iob_send.c index 89fac40..ed3afc1 100644 --- a/io/iob_send.c +++ b/io/iob_send.c @@ -20,7 +20,7 @@ int64 iob_send(int64 s,io_batch* b) { #endif if (b->bytesleft==0) return 0; - last=(iob_entry*)(((char*)array_start(&b->b))+array_bytes(&b->b)); + last=((char*)array_start(&b->b))+array_bytes(&b->b); v=alloca(b->bufs*sizeof(struct iovec)); total=0; for (;;) { diff --git a/mult/imult16.c b/mult/imult16.c index 3cff0c0..98dfb39 100644 --- a/mult/imult16.c +++ b/mult/imult16.c @@ -2,9 +2,10 @@ int imult16(int16 a,int16 b,int16* c) { int neg=(a<0); + uint16 d; if (neg) a=-a; if (b<0) { neg^=1; b=-b; } - if (umult16(a,b,c)) return 0; - if (neg) *c=-*c; + if (umult16(a,b,&d)) return 0; + *c=(neg?-d:d); return 1; } diff --git a/mult/imult32.c b/mult/imult32.c index 27393dc..98067f1 100644 --- a/mult/imult32.c +++ b/mult/imult32.c @@ -2,9 +2,10 @@ int imult32(int32 a,int32 b,int32* c) { int neg=(a<0); + uint32 d; if (neg) a=-a; if (b<0) { neg^=1; b=-b; } - if (umult32(a,b,c)) return 0; - if (neg) *c=-*c; + if (umult32(a,b,&d)) return 0; + *c=(neg?-d:d); return 1; } diff --git a/mult/imult64.c b/mult/imult64.c index f51bbeb..39d40df 100644 --- a/mult/imult64.c +++ b/mult/imult64.c @@ -2,10 +2,11 @@ int imult64(int64 a,int64 b,int64* c) { int neg=(a<0); + uint64 d; if (neg) a=-a; if (b<0) { neg^=1; b=-b; } - if (umult64(a,b,c)) return 0; - if (neg) *c=-*c; + if (umult64(a,b,&d)) return 0; + *c=(neg?-d:d); return 1; } diff --git a/socket/scan_ip6if.c b/socket/scan_ip6if.c index f132dfa..efb7626 100644 --- a/socket/scan_ip6if.c +++ b/socket/scan_ip6if.c @@ -2,9 +2,7 @@ #include "byte.h" #include #include "socket.h" -#if defined(__linux__) || defined(_SGI_SOURCE) -#include -#endif +#include "havealloca.h" unsigned int scan_ip6if(const char* src,char* ip,uint32* scope_id) { int i=scan_ip6(src,ip); diff --git a/test/b64decode.c b/test/b64decode.c index 93677e9..9288050 100644 --- a/test/b64decode.c +++ b/test/b64decode.c @@ -1,6 +1,7 @@ #include #include "buffer.h" #include "textcode.h" +#include "havealloca.h" void b64encode(const char* c) { char* buf=alloca(strlen(c)*2+4); diff --git a/test/b64encode.c b/test/b64encode.c index 726ade9..595e726 100644 --- a/test/b64encode.c +++ b/test/b64encode.c @@ -1,6 +1,7 @@ #include #include "buffer.h" #include "textcode.h" +#include "havealloca.h" void b64encode(const char* c) { char* buf=alloca(strlen(c)*2+4); diff --git a/test/cescape.c b/test/cescape.c index 3df9cd9..8b37527 100644 --- a/test/cescape.c +++ b/test/cescape.c @@ -1,7 +1,7 @@ - #include #include "buffer.h" #include "textcode.h" +#include "havealloca.h" void cescape(const char* c) { char* buf=alloca(strlen(c)*5+1); diff --git a/test/unurl.c b/test/unurl.c index 1f4a77e..260315c 100644 --- a/test/unurl.c +++ b/test/unurl.c @@ -1,6 +1,7 @@ #include #include "buffer.h" #include "textcode.h" +#include "havealloca.h" void unurl(const char* s) { char* buf; diff --git a/test/urlencode.c b/test/urlencode.c index e2dfa0f..6fab8bd 100644 --- a/test/urlencode.c +++ b/test/urlencode.c @@ -1,6 +1,7 @@ #include #include "buffer.h" #include "textcode.h" +#include "havealloca.h" void urlencode(const char* c) { char* buf=alloca(strlen(c)*3+1); diff --git a/textcode/scan_tofrom_array.c b/textcode/scan_tofrom_array.c index 3f6e393..2519d82 100644 --- a/textcode/scan_tofrom_array.c +++ b/textcode/scan_tofrom_array.c @@ -10,7 +10,7 @@ unsigned long scan_tofrom_array(unsigned long (*func)(const char*,char*,unsigned array_cat0(src); if (array_failed(src) || array_failed(dest)) return 0; needed=array_bytes(src); - x=array_start(dest)+array_bytes(dest); + x=((char*)array_start(dest))+array_bytes(dest); if (!array_allocate(dest,1,array_bytes(dest)+needed-1)) return 0; needed=func(array_start(src),x,&scanned); array_truncate(src,1,array_bytes(src)-1);