From: Ben Pfaff Date: Sun, 7 Apr 2013 21:14:25 +0000 (-0700) Subject: AUTORECODE: Trim trailing white space correctly. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c65a1f0780e9f378d8bdfb7340228b1feee291b;p=pspp AUTORECODE: Trim trailing white space correctly. The existing code trimmed off everything starting at the first space. The new version trims off only trailing spaces. Found by inspection. --- diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index b2c4d4844c..f7c4bf4d45 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009, 2010, 2012 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009, 2010, 2012, 2013 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 @@ -297,9 +297,10 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds) { const union value *from = &items[j]->from; char *recoded_value = NULL; - char *c; const int src_width = items[j]->width; union value to_val; + size_t len; + value_init (&to_val, 0); items[j]->to = direction == ASCENDING ? j + 1 : n_items - j; @@ -318,12 +319,9 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds) recoded_value = c_xasprintf ("%g", from->f); /* Remove trailing whitespace */ - for (c = recoded_value; *c != '\0'; c++) - if ( *c == ' ') - { - *c = '\0'; - break; - } + len = strlen (recoded_value); + while (len > 0 && recoded_value[len - 1] == ' ') + recoded_value[--len] = '\0'; var_add_value_label (spec->dst, &to_val, recoded_value); value_destroy (&to_val, 0);