diff mbox

[pacman-dev] makepkg: fix initialization when extracting arrays

Message ID 20180609192442.18220-1-dreisner@archlinux.org
State Accepted, archived
Headers show

Commit Message

Dave Reisner June 9, 2018, 7:24 p.m. UTC
Assuming that everything is a string leads to code which is effectively:

  a=
  a+=('bar')

This creates an array with 2 elements instead of one. Using proper array
initialization fixes this.

https://lists.archlinux.org/pipermail/pacman-dev/2018-June/022591.html
---
 scripts/libmakepkg/util/pkgbuild.sh.in | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/scripts/libmakepkg/util/pkgbuild.sh.in b/scripts/libmakepkg/util/pkgbuild.sh.in
index 10d154d1..3f8669ab 100644
--- a/scripts/libmakepkg/util/pkgbuild.sh.in
+++ b/scripts/libmakepkg/util/pkgbuild.sh.in
@@ -106,7 +106,11 @@  get_pkgbuild_attribute() {
 
 	local pkgname=$1 attrname=$2 isarray=$3 outputvar=$4
 
-	printf -v "$outputvar" %s ''
+	if (( isarray )); then
+		eval "$outputvar=()"
+	else
+		printf -v "$outputvar" %s ''
+	fi
 
 	if [[ $pkgname ]]; then
 		extract_global_variable "$attrname" "$isarray" "$outputvar"