OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.4 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../make/make-3.82-0007-copy-on-expand.patch
  5. # Copyright (C) 2012 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. From 3d11dcdc977ef7db3897663b806fe08856ca4190 Mon Sep 17 00:00:00 2001
  17. From: Christian Wiese <chris@opensde.org>
  18. Date: Mon, 22 Oct 2012 18:05:12 +0200
  19. Subject: [PATCH] copy on expand
  20. ChangeLog:
  21. 2011-08-29 Paul Smith <psmith@gnu.org>
  22. * expand.c (variable_expand_string): Always allocate a new buffer
  23. for a string we're expanding. The string we're working on can get
  24. freed while we work on it (for example if it's the value of a
  25. variable which modifies itself using an eval operation).
  26. See Savannah patch #7534 for the original report by Lubomir Rintel.
  27. tests/ChangeLog:
  28. 2011-08-29 Paul Smith <psmith@gnu.org>
  29. * scripts/features/varnesting: Test resetting of variables while
  30. expanding them. See Savannah patch #7534
  31. ---
  32. expand.c | 20 +++++----------
  33. tests/scripts/features/varnesting | 47 +++++++++++++++++++------------------
  34. 2 files changed, 31 insertions(+), 36 deletions(-)
  35. diff --git a/expand.c b/expand.c
  36. index 2315b06..9aeaa13 100644
  37. --- a/expand.c
  38. +++ b/expand.c
  39. @@ -197,7 +197,7 @@ variable_expand_string (char *line, const char *string, long length)
  40. {
  41. struct variable *v;
  42. const char *p, *p1;
  43. - char *abuf = NULL;
  44. + char *save;
  45. char *o;
  46. unsigned int line_offset;
  47. @@ -212,16 +212,11 @@ variable_expand_string (char *line, const char *string, long length)
  48. return (variable_buffer);
  49. }
  50. - /* If we want a subset of the string, allocate a temporary buffer for it.
  51. - Most of the functions we use here don't work with length limits. */
  52. - if (length > 0 && string[length] != '\0')
  53. - {
  54. - abuf = xmalloc(length+1);
  55. - memcpy(abuf, string, length);
  56. - abuf[length] = '\0';
  57. - string = abuf;
  58. - }
  59. - p = string;
  60. + /* We need a copy of STRING: due to eval, it's possible that it will get
  61. + freed as we process it (it might be the value of a variable that's reset
  62. + for example). Also having a nil-terminated string is handy. */
  63. + save = length < 0 ? xstrdup (string) : xstrndup (string, length);
  64. + p = save;
  65. while (1)
  66. {
  67. @@ -411,8 +406,7 @@ variable_expand_string (char *line, const char *string, long length)
  68. ++p;
  69. }
  70. - if (abuf)
  71. - free (abuf);
  72. + free (save);
  73. variable_buffer_output (o, "", 1);
  74. return (variable_buffer + line_offset);
  75. diff --git a/tests/scripts/features/varnesting b/tests/scripts/features/varnesting
  76. index 15d5071..d8f3ffb 100644
  77. --- a/tests/scripts/features/varnesting
  78. +++ b/tests/scripts/features/varnesting
  79. @@ -1,29 +1,30 @@
  80. -$description = "The following test creates a makefile to ...";
  81. +# -*-perl-*-
  82. +$description = "Test recursive variables";
  83. $details = "";
  84. -open(MAKEFILE,"> $makefile");
  85. -
  86. -# The Contents of the MAKEFILE ...
  87. -
  88. -print MAKEFILE "x = variable1\n"
  89. - ."variable2 := Hello\n"
  90. - ."y = \$(subst 1,2,\$(x))\n"
  91. - ."z = y\n"
  92. - ."a := \$(\$(\$(z)))\n"
  93. - ."all: \n"
  94. - ."\t\@echo \$(a)\n";
  95. -
  96. -# END of Contents of MAKEFILE
  97. -
  98. -close(MAKEFILE);
  99. -
  100. -&run_make_with_options($makefile,"",&get_logfile);
  101. -
  102. -# Create the answer to what should be produced by this Makefile
  103. -$answer = "Hello\n";
  104. -
  105. -&compare_output($answer,&get_logfile(1));
  106. +run_make_test('
  107. +x = variable1
  108. +variable2 := Hello
  109. +y = $(subst 1,2,$(x))
  110. +z = y
  111. +a := $($($(z)))
  112. +all:
  113. + @echo $(a)
  114. +',
  115. + '', "Hello\n");
  116. +
  117. +# This tests resetting the value of a variable while expanding it.
  118. +# You may only see problems with this if you're using valgrind or
  119. +# some other memory checker that poisons freed memory.
  120. +# See Savannah patch #7534
  121. +
  122. +run_make_test('
  123. +VARIABLE = $(eval VARIABLE := echo hi)$(VARIABLE)
  124. +wololo:
  125. + @$(VARIABLE)
  126. +',
  127. + '', "hi\n");
  128. 1;
  129. --
  130. 1.7.2.3