From f6cc2617336fc5d5d9e4fcebbd7d120dc5d8ebce Mon Sep 17 00:00:00 2001 From: Roland Levillain Date: Thu, 9 Jul 2020 16:58:14 +0100 Subject: [PATCH] Handle empty / undefined slice-type product variables uniformly. When checking for the emptiness / non-existence of a product variable having the type of a slice, check the length of this variable against zero, instead of checking the variable itself against `nil`, as empty / undefined list product variables may appear as nil or empty lists -- the former approach works with both nil and empty lists, while the latter only works with nil lists. Test: m nothing Bug: 159241638 Change-Id: Id436a13f8633bf698b64e6901662f67657034486 --- android/config.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/android/config.go b/android/config.go index 7073a4935..d680b652b 100644 --- a/android/config.go +++ b/android/config.go @@ -875,12 +875,12 @@ func (c *config) EnforceRROForModule(name string) bool { enforceList := c.productVariables.EnforceRROTargets // TODO(b/150820813) Some modules depend on static overlay, remove this after eliminating the dependency. exemptedList := c.productVariables.EnforceRROExemptedTargets - if exemptedList != nil { + if len(exemptedList) > 0 { if InList(name, exemptedList) { return false } } - if enforceList != nil { + if len(enforceList) > 0 { if InList("*", enforceList) { return true } @@ -891,7 +891,7 @@ func (c *config) EnforceRROForModule(name string) bool { func (c *config) EnforceRROExcludedOverlay(path string) bool { excluded := c.productVariables.EnforceRROExcludedOverlays - if excluded != nil { + if len(excluded) > 0 { return HasAnyPrefix(path, excluded) } return false @@ -1059,7 +1059,7 @@ func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool { HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) { coverage = true } - if coverage && c.config.productVariables.JavaCoverageExcludePaths != nil { + if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 { if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) { coverage = false } @@ -1088,12 +1088,12 @@ func (c *deviceConfig) GcovCoverageEnabled() bool { // NativeCoveragePaths represents any path. func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool { coverage := false - if c.config.productVariables.NativeCoveragePaths != nil { + if len(c.config.productVariables.NativeCoveragePaths) > 0 { if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) { coverage = true } } - if coverage && c.config.productVariables.NativeCoverageExcludePaths != nil { + if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 { if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) { coverage = false } @@ -1164,21 +1164,21 @@ func findOverrideValue(overrides []string, name string, errorMsg string) (newVal } func (c *config) IntegerOverflowDisabledForPath(path string) bool { - if c.productVariables.IntegerOverflowExcludePaths == nil { + if len(c.productVariables.IntegerOverflowExcludePaths) == 0 { return false } return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths) } func (c *config) CFIDisabledForPath(path string) bool { - if c.productVariables.CFIExcludePaths == nil { + if len(c.productVariables.CFIExcludePaths) == 0 { return false } return HasAnyPrefix(path, c.productVariables.CFIExcludePaths) } func (c *config) CFIEnabledForPath(path string) bool { - if c.productVariables.CFIIncludePaths == nil { + if len(c.productVariables.CFIIncludePaths) == 0 { return false } return HasAnyPrefix(path, c.productVariables.CFIIncludePaths)