Skip to content

Commit

Permalink
fix: handle nil cases for reads and writes (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krajiyah authored Dec 23, 2019
1 parent c7654c3 commit 1be6242
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ func (client *BLEClient) WriteValue(uuid string, data []byte) error {
}

func (client *BLEClient) writeValue(uuid string, data []byte) error {
if data == nil || len(data) == 0 {
return errors.New("Empty data provided. Will skip writing.")
}
c, err := client.getCharacteristic(uuid)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/characteristic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -79,6 +80,10 @@ func generateReadHandler(server *BLEServer, uuid string, load func(string, conte
server.listener.OnReadOrWriteError(err)
return
}
if data == nil || len(data) == 0 {
server.listener.OnReadOrWriteError(errors.New("empty data returned from read char loader"))
return
}
encryptedData, err := util.Encrypt(data, server.secret)
if err != nil {
server.listener.OnReadOrWriteError(err)
Expand Down

0 comments on commit 1be6242

Please sign in to comment.