mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-21 22:38:59 +00:00
fix up some OSC string parsing issues and test for them
This commit is contained in:
@@ -172,18 +172,23 @@ func argsToBuffer(args []OSCArg) []byte {
|
||||
}
|
||||
|
||||
func readOSCString(bytes []byte) (string, []byte, error) {
|
||||
//TODO(jwetzell): add error handling
|
||||
oscString := ""
|
||||
stringEndIndex := 0
|
||||
|
||||
nullByteFound := false
|
||||
for index, byteIn := range bytes {
|
||||
if byteIn == 0 {
|
||||
nullByteFound = true
|
||||
oscString = string(bytes[0:index])
|
||||
stringEndIndex = index + 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !nullByteFound {
|
||||
return "", bytes, errors.New("OSC string must be null-terminated")
|
||||
}
|
||||
|
||||
stringPadding := 4 - (stringEndIndex % 4)
|
||||
|
||||
if stringPadding < 4 {
|
||||
@@ -191,7 +196,7 @@ func readOSCString(bytes []byte) (string, []byte, error) {
|
||||
}
|
||||
|
||||
if stringEndIndex > len(bytes) {
|
||||
return "", bytes, errors.New("string data is not properly padded")
|
||||
return "", bytes, errors.New("OSC string is not properly padded")
|
||||
}
|
||||
|
||||
remainingBytes := bytes[stringEndIndex:]
|
||||
|
||||
Reference in New Issue
Block a user