Fix import of ods files with repeated column data.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 28 Aug 2021 07:10:34 +0000 (09:10 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 28 Aug 2021 07:10:34 +0000 (09:10 +0200)
Fixes bug #61078

Reported-by: Elias Tsolis
src/data/ods-reader.c
tests/automake.mk
tests/data/repeating-2.ods [new file with mode: 0644]
tests/data/spreadsheet-test.at

index 123ad3ba571c0fb67f3cbd828cbba7c853692474..b014a748d7bda81df41ddfd421c8172406133542 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2011, 2012, 2013, 2016, 2020 Free Software Foundation, Inc.
+   Copyright (C) 2011, 2012, 2013, 2016, 2020, 2021 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -909,25 +909,27 @@ ods_make_reader (struct spreadsheet *spreadsheet,
        {
          if (idx >= n_var_specs)
            {
-             var_spec = xrealloc (var_spec, sizeof (*var_spec) * (idx + 1));
+             var_spec = xrealloc (var_spec, sizeof (*var_spec) * (idx + r->rsd.col_span));
              memset (var_spec + n_var_specs,
-                     0,
-                     (idx - n_var_specs + 1) * sizeof (*var_spec));
+                     0,
+                     (idx + r->rsd.col_span - n_var_specs) * sizeof (*var_spec));
 
              var_spec [idx].name = NULL;
              n_var_specs = idx + 1;
            }
 
-         var_spec [idx].firstval.type = type;
-         var_spec [idx].firstval.text = xmlTextReaderValue (r->rsd.xtr);
-         var_spec [idx].firstval.value = val_string;
+          for (int x = 0; x < r->rsd.col_span; ++x)
+          {
+            var_spec [idx - x].firstval.type = xmlStrdup (type);
+            var_spec [idx - x].firstval.text = xmlTextReaderValue (r->rsd.xtr);
+            var_spec [idx - x].firstval.value = xmlStrdup (val_string);
+          }
 
-         val_string = NULL;
-         type = NULL;
+          free (val_string);
+          free (type);
        }
     }
 
-
   /* Create the dictionary and populate it */
   r->spreadsheet.dict = dict_create (
     CHAR_CAST (const char *, xmlTextReaderConstEncoding (r->rsd.xtr)));
index 4de61417b2ef7cf95b8898bd50abded0f386abfd..4d75aa84ab787c5201ba1654c7dbbf91ff414083 100644 (file)
@@ -274,6 +274,7 @@ tests_output_tex_strings_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/src/output
 
 EXTRA_DIST += \
        tests/coverage.sh \
+       tests/data/repeating-2.ods \
        tests/data/simple.ods \
        tests/data/simple.gnumeric \
        tests/data/sparse.ods \
diff --git a/tests/data/repeating-2.ods b/tests/data/repeating-2.ods
new file mode 100644 (file)
index 0000000..711500a
Binary files /dev/null and b/tests/data/repeating-2.ods differ
index 59836d5bc44a2beabbd69b9a5030f57ed212ec48..4056a37f6d7e3396068d91fcf7b69d982cb559a7 100644 (file)
@@ -1,5 +1,5 @@
 dnl PSPP - a program for statistical analysis.
-dnl Copyright (C) 2020 Free Software Foundation, Inc.
+dnl Copyright (C) 2020, 2021 Free Software Foundation, Inc.
 dnl
 dnl This program is free software: you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -67,7 +67,6 @@ Rows 1; Columns 8
                hi      ho                      hum     hee
 ])
 
-
 dnl If this test takes an unreasonably long time, then probably the caching
 dnl code is not working.
 dnl On my machine, this test takes about 7 seconds
@@ -83,3 +82,46 @@ Number of sheets: 3
 SPREADSHEET_TEST([simple], [--metadata], [dnl
 Number of sheets: 1
 ])
+
+
+
+AT_SETUP([spreadsheet ODS with repeating data])
+cp "$top_srcdir/tests/data/repeating-2.ods" .
+AT_DATA([ods-import.sps], [dnl
+get data /type=ods
+   /file="repeating-2.ods"
+   /sheet=index 1
+   /cellrange=range "a1:j8"
+   /readnames=on.
+
+display variables.
+list.
+])
+
+dnl Test for bug #61078
+AT_CHECK([pspp -O format=csv ods-import.sps], [0], [dnl
+Table: Variables
+Name,Position,Print Format,Write Format
+s2,1,F8.2,F8.2
+s3,2,F8.2,F8.2
+s4,3,F8.2,F8.2
+s5,4,F8.2,F8.2
+s6,5,F8.2,F8.2
+s7,6,F8.2,F8.2
+s6_A,7,F8.2,F8.2
+s7_A,8,F8.2,F8.2
+s8,9,F8.2,F8.2
+s9,10,F8.2,F8.2
+
+Table: Data List
+s2,s3,s4,s5,s6,s7,s6_A,s7_A,s8,s9
+31.00,5.00,1.00,1.00,4.00,5.00,4.00,5.00,5.00,4.00
+38.00,1.00,.00,2.00,5.00,5.00,4.00,4.00,5.00,4.00
+24.00,1.00,.00,3.00,5.00,5.00,4.00,4.00,5.00,3.00
+49.00,5.00,2.00,3.00,4.00,5.00,4.00,5.00,5.00,5.00
+30.00,1.00,.00,2.00,5.00,5.00,5.00,5.00,5.00,5.00
+33.00,5.00,2.00,2.00,5.00,5.00,5.00,5.00,5.00,5.00
+32.00,1.00,23.00,2.00,4.00,5.00,3.00,4.00,4.00,3.00
+])
+
+AT_CLEANUP