[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

From: Chris Metcalf
Subject: [bug #51266] "make -p" erroneously prints "+=" instead of ":="
Date: Mon, 19 Jun 2017 11:56:42 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36


                 Summary: "make -p" erroneously prints "+=" instead of ":="
                 Project: make
            Submitted by: cmetcalf
            Submitted on: Mon 19 Jun 2017 03:56:41 PM UTC
                Severity: 3 - Normal
              Item Group: Bug
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
       Component Version: 4.2
        Operating System: POSIX-Based
           Fixed Release: None
           Triage Status: None



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;


Reply to this item at:


  Message sent via/by Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]