You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by gi...@git.apache.org on 2017/10/17 23:06:24 UTC

[GitHub] ccollins476ad closed pull request #102: newt - Don't trace stack during syscfg access

ccollins476ad closed pull request #102: newt - Don't trace stack during syscfg access
URL: https://github.com/apache/mynewt-newt/pull/102
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/newt/syscfg/syscfg.go b/newt/syscfg/syscfg.go
index 3ebe1ce..7b861f1 100644
--- a/newt/syscfg/syscfg.go
+++ b/newt/syscfg/syscfg.go
@@ -128,17 +128,15 @@ func NewCfg() Cfg {
 	}
 }
 
+// Determines if a syscfg value is "true".  Only "" and a string representing 0
+// are considered false; everything else is true.
 func ValueIsTrue(val string) bool {
 	if val == "" {
 		return false
 	}
 
-	i, err := util.AtoiNoOct(val)
-	if err == nil && i == 0 {
-		return false
-	}
-
-	return true
+	i, success := util.AtoiNoOctTry(val)
+	return !success || i != 0
 }
 
 func (cfg *Cfg) Features() map[string]bool {
diff --git a/newt/vendor/mynewt.apache.org/newt/util/util.go b/newt/vendor/mynewt.apache.org/newt/util/util.go
index e513cf7..d1e94e5 100644
--- a/newt/vendor/mynewt.apache.org/newt/util/util.go
+++ b/newt/vendor/mynewt.apache.org/newt/util/util.go
@@ -560,7 +560,13 @@ func SortFields(wsSepStrings ...string) []string {
 	return slice
 }
 
-func AtoiNoOct(s string) (int, error) {
+// Converts the specified string to an integer.  The string can be in base-10
+// or base-16.  This is equivalent to the "0" base used in the standard
+// conversion functions, except octal is not supported (a leading zero implies
+// decimal).
+//
+// The second return value is true on success.
+func AtoiNoOctTry(s string) (int, bool) {
 	var runLen int
 	for runLen = 0; runLen < len(s)-1; runLen++ {
 		if s[runLen] != '0' || s[runLen+1] == 'x' {
@@ -574,10 +580,23 @@ func AtoiNoOct(s string) (int, error) {
 
 	i, err := strconv.ParseInt(s, 0, 0)
 	if err != nil {
-		return 0, NewNewtError(err.Error())
+		return 0, false
+	}
+
+	return int(i), true
+}
+
+// Converts the specified string to an integer.  The string can be in base-10
+// or base-16.  This is equivalent to the "0" base used in the standard
+// conversion functions, except octal is not supported (a leading zero implies
+// decimal).
+func AtoiNoOct(s string) (int, error) {
+	val, success := AtoiNoOctTry(s)
+	if !success {
+		return 0, FmtNewtError("Invalid number: \"%s\"", s)
 	}
 
-	return int(i), nil
+	return val, nil
 }
 
 func IsNotExist(err error) bool {
diff --git a/util/util.go b/util/util.go
index e513cf7..d1e94e5 100644
--- a/util/util.go
+++ b/util/util.go
@@ -560,7 +560,13 @@ func SortFields(wsSepStrings ...string) []string {
 	return slice
 }
 
-func AtoiNoOct(s string) (int, error) {
+// Converts the specified string to an integer.  The string can be in base-10
+// or base-16.  This is equivalent to the "0" base used in the standard
+// conversion functions, except octal is not supported (a leading zero implies
+// decimal).
+//
+// The second return value is true on success.
+func AtoiNoOctTry(s string) (int, bool) {
 	var runLen int
 	for runLen = 0; runLen < len(s)-1; runLen++ {
 		if s[runLen] != '0' || s[runLen+1] == 'x' {
@@ -574,10 +580,23 @@ func AtoiNoOct(s string) (int, error) {
 
 	i, err := strconv.ParseInt(s, 0, 0)
 	if err != nil {
-		return 0, NewNewtError(err.Error())
+		return 0, false
+	}
+
+	return int(i), true
+}
+
+// Converts the specified string to an integer.  The string can be in base-10
+// or base-16.  This is equivalent to the "0" base used in the standard
+// conversion functions, except octal is not supported (a leading zero implies
+// decimal).
+func AtoiNoOct(s string) (int, error) {
+	val, success := AtoiNoOctTry(s)
+	if !success {
+		return 0, FmtNewtError("Invalid number: \"%s\"", s)
 	}
 
-	return int(i), nil
+	return val, nil
 }
 
 func IsNotExist(err error) bool {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services