sys-file-reader: Tolerate nominal case size of 0 without warning.
[pspp] / utilities / pspp-dump-sav.c
index c31c02a9277185f05cb7cadc5103cd370cd1dd70..f207d8ecbf0f3362f2daf5e4f7d9245714555c86 100644 (file)
@@ -193,7 +193,7 @@ main (int argc, char *argv[])
 
       if (argc - optind > 1)
         printf ("Reading \"%s\":\n", r.file_name);
-      
+
       read_header (&r);
       while ((rec_type = read_int (&r)) != 999)
         {
@@ -237,7 +237,7 @@ main (int argc, char *argv[])
 
       fclose (r.file);
     }
-  
+
   return 0;
 }
 
@@ -444,18 +444,16 @@ read_variable_record (struct sfm_reader *r)
   if (has_variable_label == 1)
     {
       long long int offset = ftello (r->file);
-      size_t len, read_len;
-      char label[255 + 1];
+      size_t len;
+      char *label;
 
       len = read_int (r);
 
       /* Read up to 255 bytes of label. */
-      read_len = MIN (sizeof label - 1, len);
-      read_string (r, label, read_len + 1);
+      label = xmalloc (len + 1);
+      read_string (r, label, len + 1);
       printf("\t%08llx Variable label: \"%s\"\n", offset, label);
-
-      /* Skip unread label bytes. */
-      skip_bytes (r, len - read_len);
+      free (label);
 
       /* Skip label padding up to multiple of 4 bytes. */
       skip_bytes (r, ROUND_UP (len, 4) - len);
@@ -606,12 +604,6 @@ read_extension_record (struct sfm_reader *r)
       read_machine_float_info (r, size, count);
       return;
 
-    case 5:
-      /* Variable sets information.  We don't use these yet.
-         They only apply to GUIs; see VARSETS on the APPLY
-         DICTIONARY command in SPSS documentation. */
-      break;
-
     case 6:
       /* DATE variable information.  We don't use it yet, but we
          should. */
@@ -832,12 +824,6 @@ read_mrsets (struct sfm_reader *r, size_t size, size_t count)
         break;
 
       variables = text_tokenize (text, '\n');
-      if (variables == NULL)
-        {
-          sys_warn (r, "missing variable names following label "
-                    "at offset %zu in mrsets record", text_pos (text));
-          break;
-        }
 
       printf ("\t\"%s\": multiple %s set",
               name, type == MRSET_MC ? "category" : "dichotomy");
@@ -849,7 +835,10 @@ read_mrsets (struct sfm_reader *r, size_t size, size_t count)
         printf (", label \"%s\"", label);
       if (label_from_var_label)
         printf (", label from variable label");
-      printf(", variables \"%s\"\n", variables);
+      if (variables != NULL)
+        printf(", variables \"%s\"\n", variables);
+      else
+        printf(", no variables\n");
     }
   close_text_record (text);
 }
@@ -946,17 +935,17 @@ read_attributes (struct sfm_reader *r, struct text_record *text,
   const char *key;
   int index;
 
-  for (;;) 
+  for (;;)
     {
       key = text_tokenize (text, '(');
       if (key == NULL)
         return true;
-  
+
       for (index = 1; ; index++)
         {
           /* Parse the value. */
           const char *value = text_tokenize (text, '\n');
-          if (value == NULL) 
+          if (value == NULL)
             {
               sys_warn (r, "%s: Error parsing attribute value %s[%d]",
                         variable, key, index);
@@ -976,7 +965,7 @@ read_attributes (struct sfm_reader *r, struct text_record *text,
         }
 
       if (text_match (text, '/'))
-        return true; 
+        return true;
     }
 }
 
@@ -1006,10 +995,10 @@ read_ncases64 (struct sfm_reader *r, size_t size, size_t count)
 }
 
 static void
-read_datafile_attributes (struct sfm_reader *r, size_t size, size_t count) 
+read_datafile_attributes (struct sfm_reader *r, size_t size, size_t count)
 {
   struct text_record *text;
-  
+
   printf ("%08llx: datafile attributes\n", (long long int) ftello (r->file));
   text = open_text_record (r, size * count);
   read_attributes (r, text, "datafile");
@@ -1198,17 +1187,17 @@ read_unknown_extension (struct sfm_reader *r, size_t size, size_t count)
 }
 
 static void
-read_variable_attributes (struct sfm_reader *r, size_t size, size_t count) 
+read_variable_attributes (struct sfm_reader *r, size_t size, size_t count)
 {
   struct text_record *text;
-  
+
   printf ("%08llx: variable attributes\n", (long long int) ftello (r->file));
   text = open_text_record (r, size * count);
-  for (;;) 
+  for (;;)
     {
       const char *variable = text_tokenize (text, ':');
       if (variable == NULL || !read_attributes (r, text, variable))
-        break; 
+        break;
     }
   close_text_record (text);
 }
@@ -1437,9 +1426,9 @@ text_tokenize (struct text_record *text, int delimiter)
 }
 
 static bool
-text_match (struct text_record *text, int c) 
+text_match (struct text_record *text, int c)
 {
-  if (text->pos < text->size && text->buffer[text->pos] == c) 
+  if (text->pos < text->size && text->buffer[text->pos] == c)
     {
       text->pos++;
       return true;