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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Robert Morell
URL:
  <http://savannah.gnu.org/bugs/?51266>

                 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

    _______________________________________________________

Details:

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:

  <http://savannah.gnu.org/bugs/?51266>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/


_______________________________________________
Bug-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/bug-make
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Robert Morell
Update of bug #51266 (project make):

                  Status:                    None => Fixed                  
             Assigned to:                    None => psmith                
             Open/Closed:                    Open => Closed                
           Fixed Release:                    None => SCM                    
           Triage Status:                    None => Small Effort          

    _______________________________________________________

Follow-up 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.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51266>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/


_______________________________________________
Bug-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/bug-make
Loading...