Browse Source

Avoided use of function alloca() by macro Libisofs_avoid_using_allocA

and incremented version to 0.6.17
release-1.5.4.branch
Thomas Schmitt 13 years ago
parent
commit
50edfbea51
  1. 4
      configure.ac
  2. 13
      libisofs/joliet.c
  3. 10
      libisofs/libisofs.h
  4. 101
      libisofs/util.c

4
configure.ac

@ -1,4 +1,4 @@
AC_INIT([libisofs], [0.6.16], [http://libburnia-project.org])
AC_INIT([libisofs], [0.6.17], [http://libburnia-project.org])
AC_PREREQ([2.50])
dnl AC_CONFIG_HEADER([config.h])
@ -44,7 +44,7 @@ dnl If LIBISOFS_*_VERSION changes, be sure to change AC_INIT above to match.
dnl
LIBISOFS_MAJOR_VERSION=0
LIBISOFS_MINOR_VERSION=6
LIBISOFS_MICRO_VERSION=16
LIBISOFS_MICRO_VERSION=17
LIBISOFS_VERSION=$LIBISOFS_MAJOR_VERSION.$LIBISOFS_MINOR_VERSION.$LIBISOFS_MICRO_VERSION
AC_SUBST(LIBISOFS_MAJOR_VERSION)

13
libisofs/joliet.c

@ -13,6 +13,8 @@
#include "image.h"
#include "filesrc.h"
#include "eltorito.h"
#include "libisofs.h"
#include <stdlib.h>
#include <stdio.h>
@ -296,7 +298,13 @@ 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);
@ -372,6 +380,11 @@ 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;
uint16_t *dot;

10
libisofs/libisofs.h

@ -997,7 +997,7 @@ int iso_lib_is_compatible(int major, int minor, int micro);
*/
#define iso_lib_header_version_major 0
#define iso_lib_header_version_minor 6
#define iso_lib_header_version_micro 16
#define iso_lib_header_version_micro 17
/**
* Usage discussion:
@ -4785,6 +4785,14 @@ struct burn_source {
#define Libisofs_rrip_1_10_er_bugfiX yes
/* 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
/* ---------------------------- Experiments ---------------------------- */

101
libisofs/util.c

@ -191,15 +191,22 @@ int strconv(const char *str, const char *icharset, const char *ocharset,
iconv_t conv;
#endif
char *out;
char *out = NULL;
char *src;
char *ret;
int retval;
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) {
return ISO_OUT_OF_MEM;
retval = ISO_OUT_OF_MEM;
goto ex;
}
#ifdef Libisofs_with_iso_iconV
@ -210,7 +217,8 @@ int strconv(const char *str, const char *icharset, const char *ocharset,
if (conv == (iconv_t)(-1)) {
#endif
return ISO_CHARSET_CONV_ERROR;
retval = ISO_CHARSET_CONV_ERROR;
goto ex;
}
src = (char *)str;
@ -228,7 +236,8 @@ int strconv(const char *str, const char *icharset, const char *ocharset,
iconv_close(conv);
#endif
return ISO_CHARSET_CONV_ERROR;
retval = ISO_CHARSET_CONV_ERROR;
goto ex;
}
*ret = '\0';
@ -240,10 +249,20 @@ int strconv(const char *str, const char *icharset, const char *ocharset,
*output = malloc(ret - out + 1);
if (*output == NULL) {
return ISO_OUT_OF_MEM;
retval = ISO_OUT_OF_MEM;
goto ex;
}
memcpy(*output, out, ret - out + 1);
return ISO_SUCCESS;
ex:;
#ifdef Libisofs_avoid_using_allocA
if (out != NULL)
free(out);
#endif
return retval;
}
int strnconv(const char *str, const char *icharset, const char *ocharset,
@ -260,15 +279,23 @@ int strnconv(const char *str, const char *icharset, const char *ocharset,
iconv_t conv;
#endif
char *out;
char *out = NULL;
char *src;
char *ret;
int retval;
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) {
return ISO_OUT_OF_MEM;
retval = ISO_OUT_OF_MEM;
goto ex;
}
#ifdef Libisofs_with_iso_iconV
@ -279,7 +306,8 @@ int strnconv(const char *str, const char *icharset, const char *ocharset,
if (conv == (iconv_t)(-1)) {
#endif
return ISO_CHARSET_CONV_ERROR;
retval = ISO_CHARSET_CONV_ERROR;
goto ex;
}
src = (char *)str;
ret = (char *)out;
@ -296,7 +324,8 @@ int strnconv(const char *str, const char *icharset, const char *ocharset,
iconv_close(conv);
#endif
return ISO_CHARSET_CONV_ERROR;
retval = ISO_CHARSET_CONV_ERROR;
goto ex;
}
*ret = '\0';
@ -308,10 +337,20 @@ int strnconv(const char *str, const char *icharset, const char *ocharset,
*output = malloc(ret - out + 1);
if (*output == NULL) {
return ISO_OUT_OF_MEM;
retval = ISO_OUT_OF_MEM;
goto ex;
}
memcpy(*output, out, ret - out + 1);
return ISO_SUCCESS;
ex:;
#ifdef Libisofs_avoid_using_allocA
if (out != NULL)
free(out);
#endif
return retval;
}
/**
@ -934,10 +973,20 @@ char *iso_r_fileid(const char *src, size_t len, int relaxed, int forcedot)
{
char *dot;
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) {
return NULL;
goto ex;
}
dot = strrchr(src, '.');
@ -962,7 +1011,7 @@ char *iso_r_fileid(const char *src, size_t len, int relaxed, int forcedot)
}
if (lnname == 0 && lnext == 0) {
return NULL;
goto ex;
}
pos = 0;
@ -1019,6 +1068,15 @@ char *iso_r_fileid(const char *src, size_t len, int relaxed, int forcedot)
}
dest[pos] = '\0';
return strdup(dest);
ex:;
#ifdef Libisofs_avoid_using_allocA
if (dest != NULL)
free(dest);
#endif
return NULL;
}
uint16_t *iso_j_file_id(const uint16_t *src)
@ -1537,7 +1595,7 @@ void strncpy_pad(char *dest, const char *src, size_t max)
char *ucs2str(const char *buf, size_t len)
{
size_t outbytes, inbytes;
char *str, *src, *out;
char *str, *src, *out = NULL;
#ifdef Libisofs_with_iso_iconV
struct iso_iconv_handle conv;
@ -1553,7 +1611,11 @@ 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 */
@ -1570,7 +1632,7 @@ char *ucs2str(const char *buf, size_t len)
if (conv == (iconv_t)(-1)) {
#endif
return NULL;
goto ex;
}
src = (char *)buf;
str = (char *)out;
@ -1586,7 +1648,7 @@ char *ucs2str(const char *buf, size_t len)
if (n == -1) {
/* error */
return NULL;
goto ex;
}
*str = '\0';
@ -1594,6 +1656,15 @@ char *ucs2str(const char *buf, size_t len)
for (len = strlen(out) - 1; out[len] == ' ' && len > 0; --len)
out[len] = '\0';
return strdup(out);
ex:;
#ifdef Libisofs_avoid_using_allocA
if (out != NULL)
free(out);
#endif
return NULL;
}
void iso_lib_version(int *major, int *minor, int *micro)

Loading…
Cancel
Save