From: Ben Pfaff Date: Sat, 1 Jan 2011 18:47:56 +0000 (-0800) Subject: vector: Remove VAR_NAME_LEN limit for internal representation of name. X-Git-Tag: v0.7.7~74 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa61f97cbbd1246c659d4d07b302c1a02cafcd97;p=pspp-builds.git vector: Remove VAR_NAME_LEN limit for internal representation of name. Most uses of VAR_NAME_LEN within PSPP are wrong due to encoding issues: the limit applies to variable names in the encoding used by the data set, but most uses of VAR_NAME_LEN actually limit the length of a name in UTF-8. The UTF-8 representation of a name can be longer or shorter than its representation in the data set encoding, so it seems best to eliminate references to VAR_NAME_LEN entirely. --- diff --git a/src/data/vector.c b/src/data/vector.c index fd65d284..5da797c0 100644 --- a/src/data/vector.c +++ b/src/data/vector.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2011 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 @@ -15,19 +15,21 @@ along with this program. If not, see . */ #include -#include "vector.h" -#include "dictionary.h" +#include "data/vector.h" -#include -#include +#include -#include "xalloc.h" +#include "data/dictionary.h" +#include "libpspp/assertion.h" +#include "libpspp/str.h" + +#include "gl/xalloc.h" /* Vector of variables. */ struct vector { - char name[VAR_NAME_LEN + 1]; /* Name. */ + char *name; /* Name. */ struct variable **vars; /* Set of variables. */ size_t var_cnt; /* Number of variables. */ }; @@ -55,7 +57,7 @@ vector_create (const char *name, assert (var_cnt > 0); assert (var_is_plausible_name (name, false)); - str_copy_trunc (vector->name, sizeof vector->name, name); + vector->name = xstrdup (name); vector->vars = xmemdup (vars, var_cnt * sizeof *vector->vars); vector->var_cnt = var_cnt; @@ -77,7 +79,7 @@ vector_clone (const struct vector *old, struct vector *new = xmalloc (sizeof *new); size_t i; - strcpy (new->name, old->name); + new->name = xstrdup (old->name); new->vars = xnmalloc (old->var_cnt, sizeof *new->vars); new->var_cnt = old->var_cnt; @@ -96,6 +98,7 @@ vector_clone (const struct vector *old, void vector_destroy (struct vector *vector) { + free (vector->name); free (vector->vars); free (vector); }