Browse Source

Made portability improvement Libisofs_avoid_using_allocA unconditional.

release-1.5.4.branch
Thomas Schmitt 13 years ago
parent
commit
dd1cde0379
  1. 8
      libisofs/joliet.c
  2. 9
      libisofs/libisofs.h
  3. 39
      libisofs/util.c

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

9
libisofs/libisofs.h

@ -5034,14 +5034,7 @@ struct burn_source {
/* ----------------------------- Bug Fixes ----------------------------- */
/* Portability: Avoid use of function alloca().
Solaris demands to include <alloca,h>, 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 --------------------------- */

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

Loading…
Cancel
Save