pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[VAR_NAME_LEN 08/17] MODIFY VARIABLES: Eliminate VAR_NAME_LEN limit on v


From: Ben Pfaff
Subject: [VAR_NAME_LEN 08/17] MODIFY VARIABLES: Eliminate VAR_NAME_LEN limit on variable names.
Date: Sat, 5 Feb 2011 13:25:50 -0800

This is actually a general code improvement, since it eliminates memory
allocation and copying that was not actually necessary.

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.
---
 src/language/dictionary/modify-variables.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/language/dictionary/modify-variables.c 
b/src/language/dictionary/modify-variables.c
index cc84737..aae8122 100644
--- a/src/language/dictionary/modify-variables.c
+++ b/src/language/dictionary/modify-variables.c
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2010, 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
@@ -368,7 +368,7 @@ compare_variables_given_ordering (const void *a_, const 
void *b_,
 struct var_renaming
   {
     struct variable *var;
-    char new_name[VAR_NAME_LEN + 1];
+    const char *new_name;
   };
 
 /* A algo_compare_func that compares new_name members in struct
@@ -431,7 +431,7 @@ validate_var_modification (const struct dictionary *d,
   for (i = 0; i < keep_cnt; i++)
     {
       var_renaming[i].var = keep_vars[i];
-      strcpy (var_renaming[i].new_name, var_get_name (keep_vars[i]));
+      var_renaming[i].new_name = var_get_name (keep_vars[i]);
     }
 
   /* Rename variables in var_renaming array. */
@@ -449,7 +449,7 @@ validate_var_modification (const struct dictionary *d,
         continue;
       vr = var_renaming + (kv - keep_vars);
 
-      strcpy (vr->new_name, vm->new_names[i]);
+      vr->new_name = vm->new_names[i];
     }
 
   /* Sort var_renaming array by new names and check for
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]