Follow-up to bugfix #58664
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 4 Jul 2020 06:38:33 +0000 (08:38 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 4 Jul 2020 06:38:29 +0000 (08:38 +0200)
If the width of a variable changes, then implicitly so does its
missing values --- even if the number of missing values is zero.
This is because the variable's width is cached in the missing_value
struct itself.

src/data/variable.c

index 2b0dd2579dc49c39a228755faff72fb57b060a9b..593e23ca720bcbc89bae8bfde8c6312d23f0ac9a 100644 (file)
@@ -307,17 +307,15 @@ var_set_width_and_formats (struct variable *v, int new_width,
 
   ov = var_clone (v);
 
-  if (var_has_missing_values (v))
+  if (mv_is_resizable (&v->miss, new_width))
+    mv_resize (&v->miss, new_width);
+  else
     {
-      if (mv_is_resizable (&v->miss, new_width))
-       mv_resize (&v->miss, new_width);
-      else
-       {
-         mv_destroy (&v->miss);
-         mv_init (&v->miss, new_width);
-       }
-      traits |= VAR_TRAIT_MISSING_VALUES;
+      mv_destroy (&v->miss);
+      mv_init (&v->miss, new_width);
     }
+  if (new_width != var_get_width (v))
+    traits |= VAR_TRAIT_MISSING_VALUES;
 
   if (v->val_labs != NULL)
     {