Sat, 31 Jul 2004 21:12:01 +0200
trunk: changeset 1692
Call warn_err in memory reservation routines if the allocation fails.
misc.c | file | annotate | diff | comparison | revisions | |
output.c | file | annotate | diff | comparison | revisions |
--- a/misc.c Sat Jul 31 03:44:11 2004 +0200 +++ b/misc.c Sat Jul 31 21:12:01 2004 +0200 @@ -13,6 +13,7 @@ #include <ctype.h> #include "misc.h" +#include "output.h" void *malloczero(size_t size) @@ -21,6 +22,8 @@ if(p!=NULL) memset(p, 0, size); + else + warn_err(); return p; } @@ -33,8 +36,10 @@ if(newsize!=0){ p=realloc(ptr, newsize); - if(p==NULL) + if(p==NULL){ + warn_err(); return NULL; + } if(newsize>oldsize) memset((char*)p+oldsize, 0, newsize-oldsize); @@ -46,7 +51,7 @@ char *scopyn(const char *p, size_t l) { - char *pn=(char*)malloc(l+1); + char *pn=ALLOC_N(char, l+1); if(pn==NULL) return NULL; @@ -73,7 +78,7 @@ l1=strlen(p1); l2=strlen(p2); - pn=(char*)malloc(l1+l2+1); + pn=ALLOC_N(char, l1+l2+1); if(pn==NULL) return NULL; @@ -94,7 +99,7 @@ l2=strlen(p2); l3=strlen(p3); - pn=(char*)malloc(l1+l2+l3+1); + pn=ALLOC_N(char, l1+l2+l3+1); if(pn==NULL) return NULL; @@ -120,7 +125,7 @@ tlen+=l1+l2; - s=(char*)malloc(tlen); + s=ALLOC_N(char, tlen); if(s==NULL) return NULL;
--- a/output.c Sat Jul 31 03:44:11 2004 +0200 +++ b/output.c Sat Jul 31 21:12:01 2004 +0200 @@ -135,13 +135,19 @@ void libtu_asprintf(char **ret, const char *p, ...) { + *ret=NULL; CALL_V(vasprintf, (ret, p, args)); + if(*ret==NULL) + warn_err(); } void libtu_vasprintf(char **ret, const char *p, va_list args) { + *ret=NULL; vasprintf(ret, p, args); + if(*ret==NULL) + warn_err(); } @@ -233,7 +239,7 @@ char *errmsg_v(const char *p, va_list args) { char *res; - vasprintf(&res, p, args); + libtu_vasprintf(&res, p, args); return res; } @@ -244,14 +250,14 @@ if(obj!=NULL){ if(line>0) - asprintf(&res1, "%s:%d: ", obj, line); + libtu_asprintf(&res1, "%s:%d: ", obj, line); else - asprintf(&res1, "%s: ", obj); + libtu_asprintf(&res1, "%s: ", obj); }else{ if(line>0) - asprintf(&res1, "%d: ", line); + libtu_asprintf(&res1, "%d: ", line); } - vasprintf(&res2, p, args); + libtu_vasprintf(&res2, p, args); if(res1!=NULL){ if(res2==NULL) return NULL; @@ -267,7 +273,7 @@ char *errmsg_err() { char *res; - asprintf(&res, "%s\n", strerror(errno)); + libtu_asprintf(&res, "%s\n", strerror(errno)); return res; } @@ -276,9 +282,9 @@ { char *res; if(obj!=NULL) - asprintf(&res, "%s: %s\n", obj, strerror(errno)); + libtu_asprintf(&res, "%s: %s\n", obj, strerror(errno)); else - asprintf(&res, "%s\n", strerror(errno)); + libtu_asprintf(&res, "%s\n", strerror(errno)); return res; } @@ -288,14 +294,14 @@ char *res; if(obj!=NULL){ if(line>0) - asprintf(&res, "%s:%d: %s\n", obj, line, strerror(errno)); + libtu_asprintf(&res, "%s:%d: %s\n", obj, line, strerror(errno)); else - asprintf(&res, "%s: %s\n", obj, strerror(errno)); + libtu_asprintf(&res, "%s: %s\n", obj, strerror(errno)); }else{ if(line>0) - asprintf(&res, "%d: %s\n", line, strerror(errno)); + libtu_asprintf(&res, "%d: %s\n", line, strerror(errno)); else - asprintf(&res, "%s\n", strerror(errno)); + libtu_asprintf(&res, "%s\n", strerror(errno)); } return res; }