bugmake - Bugs: bug #51266, "make -p" erroneously...


bug #51266: "make -p" erroneously prints "+=" instead of ":="

Submitted by:  Chris Metcalf <cmetcalf>
Submitted on:  Mon 19 Jun 2017 03:56:41 PM UTC  
Severity:  3 - Normal Item Group:  Bug
Status:  Fixed Privacy:  Public
Assigned to:  Paul D. Smith <psmith> Open/Closed:  Closed
Component Version:  4.2 Operating System:  POSIX-Based
Fixed Release:  4.3 Triage Status:  Small Effort

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Mon 10 Jul 2017 01:59:58 AM UTC, comment #1: 

Thank you for tracking this down!

I elected to just allocate the structure using xcalloc() instead of xmalloc() to ensure everything was initialized.

The fix has been pushed to Git and will be available in the next release.

Paul D. Smith <psmith>
Project AdministratorIn charge of this item.
Mon 19 Jun 2017 03:56:41 PM UTC, original submission:  

When parsing a "make -p" output, an unexpected "+=" was seen in a context where ":=" was expected (a target-specific variable being assigned with "=" to a pattern target, e.g. "%.x: FOO = x").

The bug is extremely unstable; it required the exact build directory, and a particular amount of data in the environment.  Adding or removing unrelated environment variables ("XXX_<blah>") would cause the bug to come and go.

Running "valgrind --track-origins=yes" made the bug jump out:

 Conditional jump or move depends on uninitialised value(s)
    at 0x42265D: print_variable (variable.c:1664)
    by 0x4243F0: print_variable_data_base (variable.c:1746)
    by 0x415CC5: print_data_base (main.c:3367)
    by 0x416809: die (main.c:3443)
    by 0x407664: main (main.c:2581)
  Uninitialised value was created by a heap allocation
    at 0x4C27BE3: malloc (vg_replace_malloc.c:299)
    by 0x417698: xmalloc (misc.c:221)
    by 0x4228E1: create_pattern_var (variable.c:54)
    by 0x41D047: record_target_var (read.c:1860)
    by 0x41D047: eval (read.c:1178)
    by 0x41D8F3: eval_makefile (read.c:437)
    by 0x41CB58: eval (read.c:904)
    by 0x41DE76: eval_buffer (read.c:480)
    by 0x40E925: func_eval (function.c:1403)
    by 0x410E18: handle_function (function.c:2527)
    by 0x40B17E: variable_expand_string (expand.c:258)
    by 0x40BC12: allocated_variable_expand_for_file (expand.c:564)
    by 0x40EF0C: func_foreach (function.c:888)

Indeed, it does not appear that the variable structure allocated in create_pattern_var() is fully initialized.  As a big hammer fix, I added a memset() for the embedded "struct variable" to set it to zero; with this change, the valgrind warning is fixed, and the flaky bug disappears (although it's unstable enough that that doesn't by itself prove anything).  However, the valgrind warning points right to the code that chooses between ":=" and "+=" when printing the variable, so it seems like a strong hypothesis. 

diff --git a/variable.c b/variable.c
index 364774f05064..3f962b160019 100644
--- a/variable.c
+++ b/variable.c
@@ -88,6 +88,7 @@ create_pattern_var (const char target, const char suffix)
   p->target = target;
   p->len = len;
   p->suffix = suffix + 1;
+  memset(&p->variable, 0, sizeof(p->variable));

   if (len < 256)
     last_pattern_vars[len] = p;

Chris Metcalf <cmetcalf>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by cmetcalf (Submitted the item)
  • -email is unavailable- added by cmetcalf

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-07-10 psmith StatusNone => Fixed
        Assigned toNone => psmith
        Open/ClosedOpen => Closed
        Fixed ReleaseNone => 4.3
        Triage StatusNone => Small Effort
    2017-06-19 cmetcalf Carbon-Copy- => Added cmetcalf

    Back to the top

    Powered by Savane 3.7