]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Use the same algorithm for counting the number of words to sort as we
authorPaul Smith <psmith@gnu.org>
Mon, 2 May 2011 12:35:01 +0000 (12:35 +0000)
committerPaul Smith <psmith@gnu.org>
Mon, 2 May 2011 12:35:01 +0000 (12:35 +0000)
use to break up the list of words, so we're sure to get the same number.
Fixes Savannah bug #33125

ChangeLog
function.c
tests/ChangeLog
tests/scripts/functions/sort

index 78b6b9ebaac5cb3b6dfa4553427360f05d4bbe22..b3fed578eec586423a331735f2733bd5243aabb1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-05-02  Paul Smith  <psmith@gnu.org>
 
+       * function.c (func_sort): Use the same algorithm to count the
+       number of words we will get after the split, as we use to split.
+       Based on a patch from Matthias Hopf.  Fixes Savannah bug #33125.
+
        * make.h: Make global variable stack_limit extern.
        Fixes Savannah bug #32753.
 
index 613b8bab06ffce74235eac7436b73b6d7c2edca9..42a0193f3f92168cc57f7a5d874dab2288d449b2 100644 (file)
@@ -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];
index 3fdf5cacfe2de4e1deb51987b1aa603335ea53c0..86c6789516a2e4de423a81de00c157d531fd7c0b 100644 (file)
@@ -1,3 +1,7 @@
+2011-05-02  Paul Smith  <psmith@gnu.org>
+
+       * scripts/functions/sort: Add a test for Savannah bug #33125.
+
 2011-04-17  David A. Wheeler  <dwheeler@dwheeler.com>
 
        * scripts/features/shell_assignment: Regression for "!=" feature
index d472102d265dce32af5c07d8bc78d7bc80616862..b558910303055c99ddf47d71f8e389a8c1efe46c 100644 (file)
@@ -1,55 +1,47 @@
-$description = "The following test creates a makefile to verify\n"
-              ."the ability of make to sort lists of object. Sort\n"
-              ."will also remove any duplicate entries. This will also\n"
-              ."be tested.";
-
-$details = "The make file is built with a list of object in a random order\n"
-          ."and includes some duplicates. Make should sort all of the elements\n"
-          ."remove all duplicates\n";
-
-open(MAKEFILE,"> $makefile");
-
-# The Contents of the MAKEFILE ...
-
-print MAKEFILE "foo := moon_light days \n"
-              ."foo1:= jazz\n"
-              ."bar := captured \n"
-              ."bar2 = boy end, has rise A midnight \n"
-              ."bar3:= \$(foo)\n"
-              ."s1  := _by\n"
-              ."s2  := _and_a\n"
-              ."t1  := \$(addsuffix \$(s1), \$(bar) )\n"
-              ."t2  := \$(addsuffix \$(s2), \$(foo1) )\n" 
-              ."t3  := \$(t2) \$(t2) \$(t2) \$(t2) \$(t2) \$(t2) \$(t2) \$(t2) \$(t2) \$(t2) \n"
-              ."t4  := \$(t3) \$(t3) \$(t3) \$(t3) \$(t3) \$(t3) \$(t3) \$(t3) \$(t3) \$(t3) \n"
-              ."t5  := \$(t4) \$(t4) \$(t4) \$(t4) \$(t4) \$(t4) \$(t4) \$(t4) \$(t4) \$(t4) \n"
-              ."t6  := \$(t5) \$(t5) \$(t5) \$(t5) \$(t5) \$(t5) \$(t5) \$(t5) \$(t5) \$(t5) \n"
-              ."t7  := \$(t6) \$(t6) \$(t6) \n"
-              ."p1  := \$(addprefix \$(foo1), \$(s2) )\n"
-              ."blank:= \n"
-              ."all:\n"
-              ."\t\@echo \$(sort \$(bar2) \$(foo)  \$(addsuffix \$(s1), \$(bar) ) \$(t2) \$(bar2) \$(bar3))\n"
-              ."\t\@echo \$(sort \$(blank) \$(foo) \$(bar2) \$(t1) \$(p1) )\n"
-              ."\t\@echo \$(sort \$(foo) \$(bar2) \$(t1) \$(t4) \$(t5) \$(t7) \$(t6) )\n";
-
-
-# END of Contents of MAKEFILE
-
-close(MAKEFILE);
-
-&run_make_with_options($makefile,"",&get_logfile);
-
-# Create the answer to what should be produced by this Makefile
-$answer = "A boy captured_by days end, has jazz_and_a midnight moon_light rise\n"
-         ."A boy captured_by days end, has jazz_and_a midnight moon_light rise\n"
-         ."A boy captured_by days end, has jazz_and_a midnight moon_light rise\n";
-
-&compare_output($answer,&get_logfile(1));
+#                                                                    -*-perl-*-
+
+$description = "The following test creates a makefile to verify
+the ability of make to sort lists of object. Sort
+will also remove any duplicate entries. This will also
+be tested.";
+
+$details = "The make file is built with a list of object in a random order
+and includes some duplicates. Make should sort all of the elements
+remove all duplicates\n";
+
+run_make_test('
+foo := moon_light days
+foo1:= jazz
+bar := captured 
+bar2 = boy end, has rise A midnight 
+bar3:= $(foo)
+s1  := _by
+s2  := _and_a
+t1  := $(addsuffix $(s1), $(bar) )
+t2  := $(addsuffix $(s2), $(foo1) )
+t3  := $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) 
+t4  := $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) 
+t5  := $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) 
+t6  := $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) 
+t7  := $(t6) $(t6) $(t6) 
+p1  := $(addprefix $(foo1), $(s2) )
+blank:= 
+all:
+       @echo $(sort $(bar2) $(foo)  $(addsuffix $(s1), $(bar) ) $(t2) $(bar2) $(bar3))
+       @echo $(sort $(blank) $(foo) $(bar2) $(t1) $(p1) )
+       @echo $(sort $(foo) $(bar2) $(t1) $(t4) $(t5) $(t7) $(t6) )
+',
+              '', 'A boy captured_by days end, has jazz_and_a midnight moon_light rise
+A boy captured_by days end, has jazz_and_a midnight moon_light rise
+A boy captured_by days end, has jazz_and_a midnight moon_light rise
+');
+
+
+# Test with non-space/tab whitespace.  Note that you can't see the
+# original bug except using valgrind.
+
+run_make_test("FOO = a b\tc\rd\fe \f \f \f \f \ff
+all: ; \@echo \$(words \$(sort \$(FOO)))\n",
+              '', "5\n");
 
 1;
-
-
-
-
-
-