Fix Bug #11955.
authorBen Pfaff <blp@gnu.org>
Mon, 14 Feb 2005 00:15:56 +0000 (00:15 +0000)
committerBen Pfaff <blp@gnu.org>
Mon, 14 Feb 2005 00:15:56 +0000 (00:15 +0000)
src/ChangeLog
src/aggregate.c
tests/ChangeLog
tests/Makefile.am
tests/bugs/agg-crash-2.sh [new file with mode: 0755]

index 8cbab8f29d8ddd915f7eb54c6c009bd372ba9a58..c5fd197702edfbcca437cae4b91330e8c2ca0979 100644 (file)
@@ -1,3 +1,11 @@
+Sun Feb 13 16:11:13 2005  Ben Pfaff  <blp@gnu.org>
+
+       Fix Bug #11955.
+
+       * aggregate.c: (parse_aggregate_functions) Code cleanup.
+       Important part: get rid of spurious copying of function->format to
+       destvar->print and destvar->write.
+
 Fri Feb 11 00:08:36 2005  Ben Pfaff  <blp@gnu.org>
 
        Fix Bug #11916, which was confusing a variable's `index' member
index 46e743c9473dd9f695dcc2d9d033930517691b24..a2569837eea9d5e3c0cca06d30262f5b5276a104 100644 (file)
@@ -421,7 +421,9 @@ parse_aggregate_functions (struct agr_proc *agr)
              lex_error (_("expecting `('"));
              goto error;
            }
-       } else {
+       }
+      else
+        {
          /* Parse list of source variables. */
          {
            int pv_opts = PV_NO_SCRATCH;
@@ -514,8 +516,6 @@ parse_aggregate_functions (struct agr_proc *agr)
 
            if (src)
              {
-               int output_width;
-
                v->src = src[i];
                
                if (src[i]->type == ALPHA)
@@ -523,28 +523,29 @@ parse_aggregate_functions (struct agr_proc *agr)
                    v->function |= FSTRING;
                    v->string = xmalloc (src[i]->width);
                  }
-               
-               if (v->src->type == NUMERIC || function->alpha_type == NUMERIC)
-                 output_width = 0;
-               else
-                 output_width = v->src->width;
 
                if (function->alpha_type == ALPHA)
                  destvar = dict_clone_var (agr->dict, v->src, dest[i]);
-               else
-                 {
-                   destvar = dict_create_var (agr->dict, dest[i], output_width);
-                   if (output_width == 0)
-                     destvar->print = destvar->write = function->format;
-                   if (output_width == 0 && dict_get_weight (default_dict) != NULL
-                       && (func_index == N || func_index == N_NO_VARS
-                           || func_index == NU || func_index == NU_NO_VARS))
-                     {
-                       struct fmt_spec f = {FMT_F, 8, 2};
-                     
-                       destvar->print = destvar->write = f;
-                     }
-                 }
+               else if (v->src->type == NUMERIC
+                         || function->alpha_type == NUMERIC)
+                  {
+                    destvar = dict_create_var (agr->dict, dest[i], 0);
+                        
+                    if ((func_index == N
+                            || func_index == N_NO_VARS
+                            || func_index == NMISS)
+                        && dict_get_weight (default_dict) != NULL)
+                      {
+                        static const struct fmt_spec f8_2 = {FMT_F, 8, 2};
+                            
+                        destvar->print = destvar->write = f8_2; 
+                      }
+                    else
+                      destvar->print = destvar->write = function->format;
+                  }
+                else 
+                  destvar = dict_create_var (agr->dict, dest[i],
+                                             v->src->width);
              } else {
                v->src = NULL;
                destvar = dict_create_var (agr->dict, dest[i], 0);
@@ -568,8 +569,6 @@ parse_aggregate_functions (struct agr_proc *agr)
                destvar->label = dest_label[i];
                dest_label[i] = NULL;
              }
-           else if (function->alpha_type == ALPHA)
-             destvar->print = destvar->write = function->format;
 
            v->dest = destvar;
          }
index 5c7be71935804f7eaf8356fd1d97c0fd3738db2a..fc770a1a19e90d1eda4df0aac5f16f8534771285 100644 (file)
@@ -1,6 +1,10 @@
+Sun Feb 13 16:15:09 2005  Ben Pfaff  <blp@gnu.org>
+
+       * bugs/agg-crash-2.sh: Add new test for Bug #11955.
+
 Fri Feb 11 23:27:08 2005  Ben Pfaff  <blp@gnu.org>
 
-       * bugs/crosstabs-crash: Add new test for Bug #11916.
+       * bugs/crosstabs-crash.sh: Add new test for Bug #11916.
 
 Tue Jan 18 19:25:24 WST 2005 John Darrington <john@darrington.wattle.id.au>
 
index 757404719fc2058109e717a5736a5449ba5edf6c..f94d9b4dcb42c9bed8bb653f6bd1beb75cc70157 100644 (file)
@@ -42,6 +42,7 @@ TESTS = \
        command/use.sh \
        command/weight.sh \
        bugs/agg_crash.sh \
+       bugs/agg-crash-2.sh \
        bugs/alpha-freq.sh \
        bugs/big-input.sh \
        bugs/big-input-2.sh \
diff --git a/tests/bugs/agg-crash-2.sh b/tests/bugs/agg-crash-2.sh
new file mode 100755 (executable)
index 0000000..384c3c8
--- /dev/null
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+# This program tests for a bug which caused AGGREGATE to crash when
+# the MAX function was used.
+
+TEMPDIR=/tmp/pspp-tst-$$
+TESTFILE=$TEMPDIR/`basename $0`.sps
+
+here=`pwd`;
+
+# ensure that top_srcdir is absolute
+cd $top_srcdir; top_srcdir=`pwd`
+
+export STAT_CONFIG_PATH=$top_srcdir/config
+
+
+cleanup()
+{
+     rm -rf $TEMPDIR
+}
+
+
+fail()
+{
+    echo $activity
+    echo FAILED
+    cleanup;
+    exit 1;
+}
+
+
+no_result()
+{
+    echo $activity
+    echo NO RESULT;
+    cleanup;
+    exit 2;
+}
+
+pass()
+{
+    cleanup;
+    exit 0;
+}
+
+mkdir -p $TEMPDIR
+
+cd $TEMPDIR
+
+activity="create program"
+cat > $TESTFILE <<EOF
+DATA LIST LIST /x (F8.2) y (a25).
+
+BEGIN DATA.
+87.50 foo
+87.34 bar
+1 bar
+END DATA.
+
+
+
+AGGREGATE /BREAK=y /x=MAX(x).
+LIST /x y.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+$SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE
+if [ $? -ne 0 ] ; then no_result ; fi
+
+diff -b -B -w $TEMPDIR/pspp.list - << EOF
+1.1 DATA LIST.  Reading free-form data from the command file.
++--------+------+
+|Variable|Format|
+#========#======#
+|X       |F8.2  |
+|Y       |A25   |
++--------+------+
+
+       X                         Y
+-------- -------------------------
+   87.34 bar                       
+   87.50 foo                       
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+pass;