From dd1cde0379edb23c36c071bf1705060162879ae6 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 7 Apr 2009 12:07:48 +0200 Subject: [PATCH] Made portability improvement Libisofs_avoid_using_allocA unconditional. --- libisofs/joliet.c | 8 -------- libisofs/libisofs.h | 9 +-------- libisofs/util.c | 39 --------------------------------------- 3 files changed, 1 insertion(+), 55 deletions(-) diff --git a/libisofs/joliet.c b/libisofs/joliet.c index 82d1096..a02e048 100644 --- a/libisofs/joliet.c +++ b/libisofs/joliet.c @@ -298,13 +298,8 @@ int joliet_create_mangled_name(uint16_t *dest, uint16_t *src, int digits, int ret, pos; uint16_t *ucsnumber; char fmt[16]; - -#ifdef Libisofs_avoid_using_allocA char nstr[72]; /* The only caller of this function allocates dest with 66 elements and limits digits to < 8 */ -#else - char *nstr = alloca(digits + 1); -#endif sprintf(fmt, "%%0%dd", digits); sprintf(nstr, fmt, number); @@ -380,10 +375,7 @@ int mangle_single_dir(Ecma119Image *t, JolietNode *dir) * A max of 7 characters is good enought, it allows handling up to * 9,999,999 files with same name. */ - -#ifdef Libisofs_avoid_using_allocA /* Important: joliet_create_mangled_name() relies on digits < 72 */ -#endif while (digits < 8) { int ok, k; diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 2092c16..abf10a0 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -5034,14 +5034,7 @@ struct burn_source { /* ----------------------------- Bug Fixes ----------------------------- */ - -/* Portability: Avoid use of function alloca(). - - Solaris demands to include , FreeBSD has no such - file. It seems wiser to replace alloca() by calloc() and free() -*/ -#define Libisofs_avoid_using_allocA yes - +/* currently none being tested */ /* ---------------------------- Improvements --------------------------- */ diff --git a/libisofs/util.c b/libisofs/util.c index 9d005d3..0f9b12a 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -198,12 +198,7 @@ int strconv(const char *str, const char *icharset, const char *ocharset, inbytes = strlen(str); outbytes = (inbytes + 1) * MB_LEN_MAX; - -#ifdef Libisofs_avoid_using_allocA out = calloc(outbytes, 1); -#else - out = alloca(outbytes); -#endif if (out == NULL) { retval = ISO_OUT_OF_MEM; goto ex; @@ -254,14 +249,9 @@ int strconv(const char *str, const char *icharset, const char *ocharset, } memcpy(*output, out, ret - out + 1); retval = ISO_SUCCESS; - ex:; - -#ifdef Libisofs_avoid_using_allocA if (out != NULL) free(out); -#endif - return retval; } @@ -286,13 +276,7 @@ int strnconv(const char *str, const char *icharset, const char *ocharset, inbytes = len; outbytes = (inbytes + 1) * MB_LEN_MAX; - -#ifdef Libisofs_avoid_using_allocA out = calloc(outbytes, 1); -#else - out = alloca(outbytes); -#endif - if (out == NULL) { retval = ISO_OUT_OF_MEM; goto ex; @@ -342,14 +326,9 @@ int strnconv(const char *str, const char *icharset, const char *ocharset, } memcpy(*output, out, ret - out + 1); retval = ISO_SUCCESS; - ex:; - -#ifdef Libisofs_avoid_using_allocA if (out != NULL) free(out); -#endif - return retval; } @@ -973,17 +952,11 @@ char *iso_r_fileid(const char *src, size_t len, int relaxed, int forcedot) { char *dot, *retval = NULL; int lname, lext, lnname, lnext, pos, i; - -#ifdef Libisofs_avoid_using_allocA char *dest = NULL; dest = calloc(len + 1 + 1, 1); if (dest == NULL) goto ex; -#else - char *dest = alloca(len + 1 + 1); -#endif - if (src == NULL) { goto ex; @@ -1071,12 +1044,8 @@ char *iso_r_fileid(const char *src, size_t len, int relaxed, int forcedot) retval = strdup(dest); ex:; - -#ifdef Libisofs_avoid_using_allocA if (dest != NULL) free(dest); -#endif - return retval; } @@ -1612,11 +1581,7 @@ char *ucs2str(const char *buf, size_t len) outbytes = (inbytes+1) * MB_LEN_MAX; /* ensure enought space */ -#ifdef Libisofs_avoid_using_allocA out = calloc(outbytes, 1); -#else - out = alloca(outbytes); -#endif /* convert to local charset */ @@ -1662,12 +1627,8 @@ char *ucs2str(const char *buf, size_t len) retval = strdup(out); ex:; - -#ifdef Libisofs_avoid_using_allocA if (out != NULL) free(out); -#endif - return retval; }