trim.c: avoid zero size xnrealloc memory allocation
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 28 Jun 2020 19:51:09 +0000 (21:51 +0200)
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 28 Jun 2020 19:55:19 +0000 (21:55 +0200)
Without the patch the regression fails on test

GET with /KEEP=ALL crashes -- uncompressed

when I compile with -fsanitize=address on MacOS. The reason
is that xnrealloc is called with a zero size allocation. I
simply avoid this, although it might be perfectly o.k. to do so.

src/language/data-io/trim.c

index 2ef085e796c08d2e94ca905f94d0ec2b75fd73b5..00ebcbbe6768700336a41df2425b6d14cca1c221 100644 (file)
@@ -302,6 +302,8 @@ parse_dict_keep (struct lexer *lexer, struct dictionary *dict)
   dict_reorder_vars (dict, v, nv);
 
   /* Delete the remaining variables. */
+  if (dict_get_var_cnt (dict) == nv)
+    return true;
   v = xnrealloc (v, dict_get_var_cnt (dict) - nv, sizeof *v);
   for (i = nv; i < dict_get_var_cnt (dict); i++)
     v[i - nv] = dict_get_var (dict, i);