fix up some OSC string parsing issues and test for them

This commit is contained in:
Joel Wetzell
2026-04-13 18:17:43 -05:00
parent fbd2bf3905
commit ad3c449149
3 changed files with 31 additions and 7 deletions
+7 -2
View File
@@ -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:]