summaryrefslogtreecommitdiff
path: root/function.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2011-05-02 12:35:01 +0000
committerPaul Smith <psmith@gnu.org>2011-05-02 12:35:01 +0000
commit6979e7e43b57bba5cd7b88a8d09761fe476f01e8 (patch)
treefb7e4a58f511bd5f29675610840a6d1d9b6bec1c /function.c
parentdc90160079b692e862c6aee2709c4c7bea178aa3 (diff)
downloadgunmake-6979e7e43b57bba5cd7b88a8d09761fe476f01e8.tar.gz
Use the same algorithm for counting the number of words to sort as we
use to break up the list of words, so we're sure to get the same number. Fixes Savannah bug #33125
Diffstat (limited to 'function.c')
-rw-r--r--function.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/function.c b/function.c
index 613b8ba..42a0193 100644
--- a/function.c
+++ b/function.c
@@ -706,7 +706,7 @@ func_words (char *o, char **argv, const char *funcname UNUSED)
const char *word_iterator = argv[0];
char buf[20];
- while (find_next_token (&word_iterator, (unsigned int *) 0) != 0)
+ while (find_next_token (&word_iterator, NULL) != 0)
++i;
sprintf (buf, "%d", i);
@@ -1133,21 +1133,14 @@ func_sort (char *o, char **argv, const char *funcname UNUSED)
/* Find the maximum number of words we'll have. */
t = argv[0];
- wordi = 1;
- while (*t != '\0')
+ wordi = 0;
+ while ((p = find_next_token (&t, NULL)) != 0)
{
- char c = *(t++);
-
- if (! isspace ((unsigned char)c))
- continue;
-
+ ++t;
++wordi;
-
- while (isspace ((unsigned char)*t))
- ++t;
}
- words = xmalloc (wordi * sizeof (char *));
+ words = xmalloc ((wordi == 0 ? 1 : wordi) * sizeof (char *));
/* Now assign pointers to each string in the array. */
t = argv[0];