From 46a7a7b189e2df740043496c16d9f7c665b7a828 Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@gnu.org>
Date: Wed, 16 Sep 2009 20:19:34 -0700
Subject: [PATCH] Don't pad variable labels written to system files.

Previously, the code to write variable labels to system files accidentally
padded out the variable labels on the right with spaces to a multiple of 4
bytes in length.  With this commit, variable labels will no longer be
padded.

This fixes a genuine bug for variable labels longer than 252 bytes, which
previously were padded out to 256 bytes.  Variable labels are limited to
a maximum of 255 bytes, so PSPP refused to read such files.

Reported-by: Robert Westlund <rob@kinesissurvey.com>
---
 src/data/sys-file-writer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c
index 7804e5914f..001b78f162 100644
--- a/src/data/sys-file-writer.c
+++ b/src/data/sys-file-writer.c
@@ -436,8 +436,9 @@ write_variable (struct sfm_writer *w, const struct variable *v)
   if (var_has_label (v))
     {
       const char *label = var_get_label (v);
-      size_t padded_len = ROUND_UP (MIN (strlen (label), 255), 4);
-      write_int (w, padded_len);
+      size_t label_len = MIN (strlen (label), 255);
+      size_t padded_len = ROUND_UP (label_len, 4);
+      write_int (w, label_len);
       write_string (w, label, padded_len);
     }
 
-- 
2.30.2