commit b1bcebf835ca9c010527dc192a9ed083ce31c7cc
parent 6a1a73b2c0161bf7bd456df97c584b40827bbf7b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 24 Nov 2015 10:37:53 +0100
Fix the parsing of the super shape distribution
A super-shape distribution with empty superformula may lead to
memory corruption.
.
Diffstat:
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/schiff_args.c b/src/schiff_args.c
@@ -387,13 +387,18 @@ parse_super_formula(const char* str, struct schiff_param formula[6])
{
struct str buf;
char* tk;
- char* tk_ctx;
+ char* tk_ctx = NULL;
int i;
res_T res = RES_OK;
ASSERT(str && formula);
str_init(&mem_default_allocator, &buf);
+ if(!str) {
+ fprintf(stderr, "Missing super formula.\n");
+ res = RES_BAD_ARG;
+ }
+
res = str_set(&buf, str);
if(res != RES_OK) {
fprintf(stderr,
@@ -402,6 +407,9 @@ parse_super_formula(const char* str, struct schiff_param formula[6])
goto error;
}
+ /* Avoid an overzealos GCC warn that assumes that str_get(&buf) may be NULL */
+ tk_ctx = NULL;
+
tk = strtok_r(str_get(&buf), ",", &tk_ctx);
for(i=0; tk && i < 6; ++i ) {
res = parse_param_distribution(tk, formula + i);