From: John Darrington Date: Wed, 6 Apr 2016 07:38:56 +0000 (+0200) Subject: Fixed crash on FLIP vs. invalid variable names. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=edcc44c873fcd39364d654ab53553960a7be0d29;p=pspp Fixed crash on FLIP vs. invalid variable names. FLIP would crash if the designated new names were not valid names. For example "TO", "BY", "" etc. Found by zzuf. --- diff --git a/src/language/stats/flip.c b/src/language/stats/flip.c index 9d3b0a6346..7c28d3a1da 100644 --- a/src/language/stats/flip.c +++ b/src/language/stats/flip.c @@ -271,9 +271,15 @@ make_new_var (struct dictionary *dict, const char *name_) } *cp = '\0'; + if (strlen (name) == 0) + { + free (name); + name = xstrdup ("v"); + } + /* Use the mangled name, if it is available, or add numeric extensions until we find one that is. */ - if (!dict_create_var (dict, name, 0)) + if (!id_is_plausible (name, false) || !dict_create_var (dict, name, 0)) { int len = strlen (name); int i; @@ -284,7 +290,7 @@ make_new_var (struct dictionary *dict, const char *name_) strncpy (n, name, ofs); sprintf (&n[ofs], "%d", i); - if (dict_create_var (dict, n, 0)) + if (id_is_plausible (n, false) && dict_create_var (dict, n, 0)) break; } } diff --git a/tests/language/stats/flip.at b/tests/language/stats/flip.at index 22058f23bf..cd9ee98cfa 100644 --- a/tests/language/stats/flip.at +++ b/tests/language/stats/flip.at @@ -98,3 +98,30 @@ flip. AT_CHECK([pspp -O format=csv flip.sps], [1], [ignore]) AT_CLEANUP + + + +AT_SETUP([FLIP with invalid variable names]) + +AT_DATA([flip.sps], [dnl +data list notable list /N (a3) a b c d *. +begin data. +"" 1 2 3 4 +BY 1 2 3 4 +end data. + +flip newnames=n. + +list. +]) + +AT_CHECK([pspp -O format=csv flip.sps], [0], [dnl +Table: Data List +CASE_LBL,v,BY1 +a ,1.00,1.00 +b ,2.00,2.00 +c ,3.00,3.00 +d ,4.00,4.00 +]) + +AT_CLEANUP