summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony J. Bentley <anthony@cathet.us>2013-04-27 01:01:52 (GMT)
committer Vincent Sanders <vince@netsurf-browser.org>2013-04-27 12:28:47 (GMT)
commita4e3ccd6abb97d05121635112bdca44fc0e440b0 (patch)
tree699ad88c55b44c3e82f2180b6096666919127f19
parenta6fd64ee6ca004627cefc7d80e036707bea22bf9 (diff)
downloadlibparserutils-a4e3ccd6abb97d05121635112bdca44fc0e440b0.tar.gz
libparserutils-a4e3ccd6abb97d05121635112bdca44fc0e440b0.tar.bz2
Don't use the nonportable alloca() during tests.
-rw-r--r--test/cscodec-8859.c12
-rw-r--r--test/cscodec-ext8.c12
-rw-r--r--test/cscodec-utf16.c8
-rw-r--r--test/cscodec-utf8.c8
4 files changed, 30 insertions, 10 deletions
diff --git a/test/cscodec-8859.c b/test/cscodec-8859.c
index bd7dfa4..d47fb2a 100644
--- a/test/cscodec-8859.c
+++ b/test/cscodec-8859.c
@@ -169,7 +169,7 @@ bool handle_line(const char *data, size_t datalen, void *pw)
for (end = enc; !isspace(*end); end++)
;
- enc_name = alloca(end - enc + 1);
+ enc_name = malloc(end - enc + 1);
memcpy(enc_name, enc, end - enc);
enc_name[end - enc] = 0;
@@ -178,6 +178,8 @@ bool handle_line(const char *data, size_t datalen, void *pw)
PARSERUTILS_OK);
ctx->hadenc = true;
+
+ free(enc_name);
}
} else {
if (ctx->indata) {
@@ -197,7 +199,7 @@ void run_test(line_ctx *ctx)
{
static int testnum;
size_t destlen = ctx->bufused * 4;
- uint8_t *dest = alloca(destlen);
+ uint8_t *dest = malloc(destlen);
uint8_t *pdest = dest;
const uint8_t *psrc = ctx->buf;
size_t srclen = ctx->bufused;
@@ -213,7 +215,7 @@ void run_test(line_ctx *ctx)
&pdest, &destlen) == ctx->exp_ret);
} else {
size_t templen = ctx->bufused * 4;
- uint8_t *temp = alloca(templen);
+ uint8_t *temp = malloc(templen);
uint8_t *ptemp = temp;
const uint8_t *ptemp2;
size_t templen2;
@@ -237,6 +239,8 @@ void run_test(line_ctx *ctx)
assert(templen2 == 0);
assert(temp + (ctx->bufused * 4 - templen) == ptemp2);
}
+
+ free(temp);
}
if (ctx->exp_ret == PARSERUTILS_OK) {
assert(srclen == 0);
@@ -259,5 +263,7 @@ void run_test(line_ctx *ctx)
assert(pdest == dest + ctx->expused);
assert(memcmp(dest, ctx->exp, ctx->expused) == 0);
+
+ free(dest);
}
diff --git a/test/cscodec-ext8.c b/test/cscodec-ext8.c
index bd7dfa4..d47fb2a 100644
--- a/test/cscodec-ext8.c
+++ b/test/cscodec-ext8.c
@@ -169,7 +169,7 @@ bool handle_line(const char *data, size_t datalen, void *pw)
for (end = enc; !isspace(*end); end++)
;
- enc_name = alloca(end - enc + 1);
+ enc_name = malloc(end - enc + 1);
memcpy(enc_name, enc, end - enc);
enc_name[end - enc] = 0;
@@ -178,6 +178,8 @@ bool handle_line(const char *data, size_t datalen, void *pw)
PARSERUTILS_OK);
ctx->hadenc = true;
+
+ free(enc_name);
}
} else {
if (ctx->indata) {
@@ -197,7 +199,7 @@ void run_test(line_ctx *ctx)
{
static int testnum;
size_t destlen = ctx->bufused * 4;
- uint8_t *dest = alloca(destlen);
+ uint8_t *dest = malloc(destlen);
uint8_t *pdest = dest;
const uint8_t *psrc = ctx->buf;
size_t srclen = ctx->bufused;
@@ -213,7 +215,7 @@ void run_test(line_ctx *ctx)
&pdest, &destlen) == ctx->exp_ret);
} else {
size_t templen = ctx->bufused * 4;
- uint8_t *temp = alloca(templen);
+ uint8_t *temp = malloc(templen);
uint8_t *ptemp = temp;
const uint8_t *ptemp2;
size_t templen2;
@@ -237,6 +239,8 @@ void run_test(line_ctx *ctx)
assert(templen2 == 0);
assert(temp + (ctx->bufused * 4 - templen) == ptemp2);
}
+
+ free(temp);
}
if (ctx->exp_ret == PARSERUTILS_OK) {
assert(srclen == 0);
@@ -259,5 +263,7 @@ void run_test(line_ctx *ctx)
assert(pdest == dest + ctx->expused);
assert(memcmp(dest, ctx->exp, ctx->expused) == 0);
+
+ free(dest);
}
diff --git a/test/cscodec-utf16.c b/test/cscodec-utf16.c
index 3eadaca..f29e4d1 100644
--- a/test/cscodec-utf16.c
+++ b/test/cscodec-utf16.c
@@ -255,7 +255,7 @@ void run_test(line_ctx *ctx)
{
static int testnum;
size_t destlen = ctx->bufused * 4;
- uint8_t *dest = alloca(destlen);
+ uint8_t *dest = malloc(destlen);
uint8_t *pdest = dest;
const uint8_t *psrc = ctx->buf;
size_t srclen = ctx->bufused;
@@ -271,7 +271,7 @@ void run_test(line_ctx *ctx)
&pdest, &destlen) == ctx->exp_ret);
} else {
size_t templen = ctx->bufused * 4;
- uint8_t *temp = alloca(templen);
+ uint8_t *temp = malloc(templen);
uint8_t *ptemp = temp;
const uint8_t *ptemp2;
size_t templen2;
@@ -295,6 +295,8 @@ void run_test(line_ctx *ctx)
assert(templen2 == 0);
assert(temp + (ctx->bufused * 4 - templen) == ptemp2);
}
+
+ free(temp);
}
if (ctx->exp_ret == PARSERUTILS_OK) {
assert(srclen == 0);
@@ -317,5 +319,7 @@ void run_test(line_ctx *ctx)
assert(pdest == dest + ctx->expused);
assert(memcmp(dest, ctx->exp, ctx->expused) == 0);
+
+ free(dest);
}
diff --git a/test/cscodec-utf8.c b/test/cscodec-utf8.c
index c36961e..6b1d4de 100644
--- a/test/cscodec-utf8.c
+++ b/test/cscodec-utf8.c
@@ -180,7 +180,7 @@ void run_test(line_ctx *ctx)
{
static int testnum;
size_t destlen = ctx->bufused * 4;
- uint8_t *dest = alloca(destlen);
+ uint8_t *dest = malloc(destlen);
uint8_t *pdest = dest;
const uint8_t *psrc = ctx->buf;
size_t srclen = ctx->bufused;
@@ -196,7 +196,7 @@ void run_test(line_ctx *ctx)
&pdest, &destlen) == ctx->exp_ret);
} else {
size_t templen = ctx->bufused * 4;
- uint8_t *temp = alloca(templen);
+ uint8_t *temp = malloc(templen);
uint8_t *ptemp = temp;
const uint8_t *ptemp2;
size_t templen2;
@@ -220,6 +220,8 @@ void run_test(line_ctx *ctx)
assert(templen2 == 0);
assert(temp + (ctx->bufused * 4 - templen) == ptemp2);
}
+
+ free(temp);
}
if (ctx->exp_ret == PARSERUTILS_OK) {
assert(srclen == 0);
@@ -242,5 +244,7 @@ void run_test(line_ctx *ctx)
assert(pdest == dest + ctx->expused);
assert(memcmp(dest, ctx->exp, ctx->expused) == 0);
+
+ free(dest);
}