Changeset: e58514df3b82 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e58514df3b82
Modified Files:
common/stream/stream.c
Branch: Aug2011
Log Message:
Fix compilation error.
Some more sophistated compilers complained about
error: not protecting local variables: variable length buffer
Fix this by not using alloca here.
diffs (63 lines):
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -1854,12 +1854,17 @@
struct icstream *ic = (struct icstream *) s->stream_data.p;
ICONV_CONST char *inbuf = (ICONV_CONST char *) buf;
size_t inbytesleft = elmsize * cnt;
+ char *bf = NULL;
/* if unconverted data from a previous call remains, add it to
the start of the new data, using temporary space */
if (ic->buflen > 0) {
- char *bf = alloca(ic->buflen + inbytesleft);
-
+ bf = malloc(ic->buflen + inbytesleft);
+ if (bf == NULL) {
+ /* cannot allocate memory */
+ s->errnr = MNSTR_WRITE_ERROR;
+ return -1;
+ }
memcpy(bf, ic->buffer, ic->buflen);
memcpy(bf + ic->buflen, buf, inbytesleft);
buf = bf;
@@ -1875,6 +1880,8 @@
case EILSEQ:
/* invalid multibyte sequence encountered */
s->errnr = MNSTR_WRITE_ERROR;
+ if (bf)
+ free(bf);
return -1;
case EINVAL:
/* incomplete multibyte sequence encountered */
@@ -1885,10 +1892,14 @@
if (inbytesleft > sizeof(ic->buffer)) {
/* ridiculously long multibyte
sequence, so return error */
s->errnr = MNSTR_WRITE_ERROR;
+ if (bf)
+ free(bf);
return -1;
}
memcpy(ic->buffer, inbuf, inbytesleft);
ic->buflen = inbytesleft;
+ if (bf)
+ free(bf);
return (ssize_t) cnt;
case E2BIG:
/* not enough space in output buffer */
@@ -1896,11 +1907,15 @@
default:
/* cannot happen (according to manual) */
s->errnr = MNSTR_WRITE_ERROR;
+ if (bf)
+ free(bf);
return -1;
}
}
mnstr_write(ic->s, ic->buffer, 1, sizeof(ic->buffer) -
outbytesleft);
}
+ if (bf)
+ free(bf);
return (ssize_t) cnt;
}
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list