From: Friedrich Beckmann Date: Sun, 28 Jun 2020 19:51:09 +0000 (+0200) Subject: trim.c: avoid zero size xnrealloc memory allocation X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2039bc0694b89d26065899d9ed20f9bb42426f4;p=pspp trim.c: avoid zero size xnrealloc memory allocation 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. --- diff --git a/src/language/data-io/trim.c b/src/language/data-io/trim.c index 2ef085e796..00ebcbbe67 100644 --- a/src/language/data-io/trim.c +++ b/src/language/data-io/trim.c @@ -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);