From 262e633cc1b745e82ce56d6d31c94e574ae79caa Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 7 Feb 2012 21:18:08 -0800 Subject: [PATCH] dictionary: Truncate file label in dictionary encoding, not UTF-8. The limiting factor is bytes in the on-disk format and so there's no point in truncating in terms of the in-memory format. --- src/data/dictionary.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 2d99f6d72c..b64d84a2ca 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1250,15 +1250,18 @@ dict_get_label (const struct dictionary *d) return d->label; } -/* Sets D's file label to LABEL, truncating it to a maximum of 60 - characters. +/* Sets D's file label to LABEL, truncating it to at most 60 bytes in D's + encoding. Removes D's label if LABEL is null or the empty string. */ void dict_set_label (struct dictionary *d, const char *label) { free (d->label); - d->label = label != NULL && label[0] != '\0' ? xstrndup (label, 60) : NULL; + if (label == NULL || label[0] == '\0') + d->label = NULL; + else + d->label = utf8_encoding_trunc (label, d->encoding, 60); } /* Returns the documents for D, as an UTF-8 encoded string_array. The -- 2.30.2