Skip to content

Commit

Permalink
[bugfix] panic when bluetooth.plist parse error
Browse files Browse the repository at this point in the history
Signed-off-by: shadowhao <shadowhao.tencent.com>
  • Loading branch information
shadowhao committed Jan 28, 2022
1 parent a9b9578 commit c9811cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func show() {
{"DeviceCache", device.Addr, "BatteryPercentRight"},
}
batteries := pp.GetAttrByNames(attrs)
battery = fmt.Sprintf("C:%v%%/L:%v%%/R:%v%%", batteries[0], batteries[1], batteries[2])
if len(batteries) == len(attrs[0]) {
battery = fmt.Sprintf("C:%v%%/L:%v%%/R:%v%%", batteries[0], batteries[1], batteries[2])
}
}

var subInfo, nextOP string
Expand Down
10 changes: 9 additions & 1 deletion plist/plist.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ func (i *Info) GetAttrByNames(attrKeys [][]string) []interface{} {
var attr interface{}
var mapattr map[string]interface{}
var res []interface{}
var ok bool

for _, condition := range attrKeys {
attr = i.PlistData
for _, c := range condition {
mapattr = attr.(map[string]interface{})
// https://github.com/haoguanguan/bluetooth_flow/issues/2
if attr == nil {
break
}
mapattr, ok = attr.(map[string]interface{})
if !ok {
break
}
attr = mapattr[c]
}
res = append(res, attr)
Expand Down

0 comments on commit c9811cd

Please sign in to comment.