Fix bug #22037.
[pspp-builds.git] / src / language / stats / crosstabs.q
index 3bffa2a32f5839f712548f8f07e4f765fe719c6c..fcfccc39a251c2fbbfffbda7a6913207a70d1757 100644 (file)
@@ -637,12 +637,14 @@ calc_general (struct ccase *c, const struct dataset *ds)
              te->values[j].f = case_num (c, x->vars[j]);
            else
              {
-               memcpy (te->values[j].s, case_str (c, x->vars[j]),
-                        var_get_width (x->vars[j]));
+                size_t n = var_get_width (x->vars[j]);
+                if (n > MAX_SHORT_STRING)
+                  n = MAX_SHORT_STRING;
+               memcpy (te->values[j].s, case_str (c, x->vars[j]), n);
 
                /* Necessary in order to simplify comparisons. */
                memset (&te->values[j].s[var_get_width (x->vars[j])], 0,
-                       sizeof (union value) - var_get_width (x->vars[j]));
+                       sizeof (union value) - n);
              }
          }
       }