@item int32 label_len;
This field is present only if @code{has_var_label} is set to 1. It is
-set to the length, in characters, of the variable label, which must be a
-number between 0 and 120.
+set to the length, in characters, of the variable label. The
+documented maximum length varies from 120 to 255 based on SPSS
+version, but some files have been seen with longer labels. PSPP
+accepts longer labels and truncates them to 255 bytes on input.
@item char label[];
This field is present only if @code{has_var_label} is set to 1. It has
following value label variables record (see below) is read.
@item char label_len;
-The label's length, in bytes.
+The label's length, in bytes. The documented maximum length varies
+from 60 to 120 based on SPSS version. PSPP supports value labels up
+to 255 bytes long.
@item char label[];
@code{label_len} bytes of the actual label, followed by up to 7 bytes
sys_error (r, _("Variable label indicator field is not 0 or 1."));
if (has_variable_label == 1)
{
- size_t len;
+ size_t len, read_len;
char label[255 + 1];
len = read_int (r);
- if (len >= sizeof label)
- sys_error (r, _("Variable %s has label of invalid length %zu."),
- name, len);
- read_string (r, label, len + 1);
+
+ /* Read up to 255 bytes of label. */
+ read_len = MIN (sizeof label - 1, len);
+ read_string (r, label, read_len + 1);
var_set_label (var, label);
+ /* Skip unread label bytes. */
+ skip_bytes (r, len - read_len);
+
+ /* Skip label padding up to multiple of 4 bytes. */
skip_bytes (r, ROUND_UP (len, 4) - len);
}
if (has_variable_label == 1)
{
long long int offset = ftello (r->file);
- size_t len;
+ size_t len, read_len;
char label[255 + 1];
len = read_int (r);
- if (len >= sizeof label)
- sys_error (r, _("Variable %s has label of invalid length %zu."),
- name, len);
- read_string (r, label, len + 1);
+
+ /* Read up to 255 bytes of label. */
+ read_len = MIN (sizeof label - 1, len);
+ read_string (r, label, read_len + 1);
printf("\t%08llx Variable label: \"%s\"\n", offset, label);
+ /* Skip unread label bytes. */
+ skip_bytes (r, len - read_len);
+
+ /* Skip label padding up to multiple of 4 bytes. */
skip_bytes (r, ROUND_UP (len, 4) - len);
}