Yuri Chornoivan contributed some typo fixes
[pspp] / src / data / ods-reader.c
index 123ad3ba571c0fb67f3cbd828cbba7c853692474..dc861f29abcdab8916fc0b5d0534726467a8dc80 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
@@ -129,7 +129,7 @@ struct cache_datum
 {
   struct hmap_node node;
 
-  /* The the number of the sheet.  */
+  /* The number of the sheet.  */
   int sheet;
 
   /* The cell's row.  */
@@ -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)));
@@ -1077,7 +1079,7 @@ ods_file_casereader_read (struct casereader *reader UNUSED, void *r_)
           r->rsd.node_type == XML_READER_TYPE_TEXT)
        {
          int col;
-         struct xml_value *xmv = xzalloc (sizeof *xmv);
+         struct xml_value *xmv = XZALLOC (struct xml_value);
          xmv->text = xmlTextReaderValue (r->rsd.xtr);
          xmv->value = val_string;
          val_string = NULL;
@@ -1092,7 +1094,7 @@ ods_file_casereader_read (struct casereader *reader UNUSED, void *r_)
                continue;
              if (r->spreadsheet.stop_col != -1 && idx > r->spreadsheet.stop_col - r->spreadsheet.start_col)
                break;
-             if (idx >= dict_get_var_cnt (r->spreadsheet.dict))
+             if (idx >= dict_get_n_vars (r->spreadsheet.dict))
                break;
 
               var = dict_get_var (r->spreadsheet.dict, idx);
@@ -1161,7 +1163,7 @@ init_reader (struct ods_reader *r, bool report_errors,
 struct spreadsheet *
 ods_probe (const char *filename, bool report_errors)
 {
-  struct ods_reader *r = xzalloc (sizeof *r);
+  struct ods_reader *r = XZALLOC (struct ods_reader);
 
   struct zip_reader *zr;
   char *error = zip_reader_create (filename, &zr);