You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/03/28 22:41:57 UTC

[60/67] [abbrv] incubator-mynewt-newtmgr git commit: nmxact - Fix parse error on empty byte string.

nmxact - Fix parse error on empty byte string.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/commit/9cae5044
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/tree/9cae5044
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/diff/9cae5044

Branch: refs/heads/master
Commit: 9cae50447c17a177d0f6e5a94090acc5b8f65ac2
Parents: ea22bd0
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Mar 28 13:07:32 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Mar 28 15:38:36 2017 -0700

----------------------------------------------------------------------
 nmxact/nmble/ble_proto.go | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9cae5044/nmxact/nmble/ble_proto.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_proto.go b/nmxact/nmble/ble_proto.go
index 80ef2a0..85a26f8 100644
--- a/nmxact/nmble/ble_proto.go
+++ b/nmxact/nmble/ble_proto.go
@@ -763,12 +763,18 @@ func (bb *BleBytes) UnmarshalJSON(data []byte) error {
 		return err
 	}
 
+	// strings.Split() appears to return { nil } when passed an empty string.
+	if len(s) == 0 {
+		return nil
+	}
+
 	toks := strings.Split(strings.ToLower(s), ":")
 	bb.Bytes = make([]byte, len(toks))
 
 	for i, t := range toks {
 		if !strings.HasPrefix(t, "0x") {
-			return errors.New("Byte stream contains invalid token: " + t)
+			return fmt.Errorf(
+				"Byte stream contains invalid token; token=%s stream=%s", t, s)
 		}
 
 		u64, err := strconv.ParseUint(t, 0, 8)