Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Jan 2012 21:23:43 -0600 (CST)
From:      Stephen Montgomery-Smith <stephen@wilberforce.math.missouri.edu>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/164361: make handles "+=" incorrectly when the variable has zero length
Message-ID:  <201201220323.q0M3Nh1b025121@wilberforce.math.missouri.edu>
Resent-Message-ID: <201201220330.q0M3UFuI028232@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         164361
>Category:       bin
>Synopsis:       make handles "+=" incorrectly when the variable has zero length
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jan 22 03:30:14 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Stephen Montgomery-Smith
>Release:        FreeBSD 8.2-STABLE amd64
>Organization:
>Environment:
System: FreeBSD wilberforce 8.2-STABLE FreeBSD 8.2-STABLE #0: Sat Dec 24 10:10:36 CST 2011 stephen@wilberforce:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:

make handles "+=" incorrectly when the variable has zero length.

This creates a mystery space if one does something like

cd /usr/ports/math/lapack
make -V LDFLAGS

because of many lines in /usr/share/mk/sys.mk like
LDFLAGS		?=

>How-To-Repeat:
Create a Makefile containing
XXX=
XXX+=	xxx

all:
	echo +${XXX}+


make produces the output
echo + xxx+
+ xxx+

>Fix:

	

diff -ur usr.bin/make/var.c-orig usr.bin/make/var.c
--- usr.bin/make/var.c-orig	2012-01-21 21:10:50.000000000 -0600
+++ usr.bin/make/var.c	2012-01-21 21:12:05.000000000 -0600
@@ -1101,7 +1101,8 @@
 	if (v == NULL) {
 		VarAdd(n, val, ctxt);
 	} else {
-		Buf_AddByte(v->val, (Byte)' ');
+		if (Buf_Size(v->val) != 0)
+			Buf_AddByte(v->val, (Byte)' ');
 		Buf_Append(v->val, val);
 		DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, Buf_Data(v->val)));
 	}

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201220323.q0M3Nh1b025121>