From fad701f04b435a42e2feabd90174274f04a23d4d Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 8 Aug 2010 11:39:16 +0200 Subject: [PATCH] Aggregate: Fixed bug when attempting to create duplicate variable This change fixes a segfault which occured if AGGREGATE MODE=ADDVARIABLES attempted to create a variable which already exists in the dictionary. Added a test to check for this bug. --- src/language/stats/aggregate.c | 16 ++++++++----- tests/language/stats/aggregate.at | 40 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index b2132ec71a..7625a6f1a7 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -637,12 +637,16 @@ parse_aggregate_functions (struct lexer *lexer, const struct dictionary *dict, struct fmt_spec f; v->src = NULL; destvar = dict_create_var (agr->dict, dest[i], 0); - if (func_index == N && dict_get_weight (dict) != NULL) - f = fmt_for_output (FMT_F, 8, 2); - else - f = function->format; - var_set_both_formats (destvar, &f); - } + if (destvar != NULL) + { + if ((func_index == N || func_index == NMISS) + && dict_get_weight (dict) != NULL) + f = fmt_for_output (FMT_F, 8, 2); + else + f = function->format; + var_set_both_formats (destvar, &f); + } + } if (!destvar) { diff --git a/tests/language/stats/aggregate.at b/tests/language/stats/aggregate.at index 3c10d3ad40..da078f84d1 100644 --- a/tests/language/stats/aggregate.at +++ b/tests/language/stats/aggregate.at @@ -249,3 +249,43 @@ x,cn,y,sum,mean,median ]) AT_CLEANUP + + +AT_SETUP([AGGREGATE buggy duplicate variables]) +dnl Test for a bug which crashed when duplicated +dnl variables were attempted. +AT_DATA([dup-variables.sps], + [DATA LIST NOTABLE LIST /x * . +begin data +1 +1 +1 +1 +2 +2 +2 +3 +3 +3 +3 +3 +3 +end data. + +AGGREGATE OUTFILE=* MODE=ADDVARIABLES + /BREAK= x + /N_BREAK = N. + +AGGREGATE OUTFILE=* MODE=ADDVARIABLES + /BREAK= x + /N_BREAK = N. +]) + +AT_CHECK([pspp -O format=csv dup-variables.sps], [1], +["dup-variables.sps:24: error: AGGREGATE: Variable name N_BREAK is not unique within the aggregate file dictionary, which contains the aggregate variables and the break variables." + +dup-variables.sps:24: error: Stopping syntax file processing here to avoid a cascade of dependent command failures. +]) + + +AT_CLEANUP \ No newline at end of file -- 2.30.2