Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't send empty string #17

Open
avlapp opened this issue Jan 21, 2023 · 1 comment · May be fixed by #24
Open

can't send empty string #17

avlapp opened this issue Jan 21, 2023 · 1 comment · May be fixed by #24

Comments

@avlapp
Copy link

avlapp commented Jan 21, 2023

Sending a empty string doesn't seems to work using osc.String("")

Error 9912

https://github.com/radarsat1/liblo/blob/cb6f43da7cc137a2a64f129cdbb54638658a0d30/lo/lo_errors.h#L35
#define LO_EINVALIDARG 9912

@vlappa
Copy link

vlappa commented Oct 1, 2023

I think I found the cause:

SendTo calls Bytes method on packet (a osc message)
https://github.com/scgolang/osc/blob/master/udp.go#L106C29-L106C29

Bytes method of message calls Bytes method for arguments, in this case a String
https://github.com/scgolang/osc/blob/master/message.go#L58

https://github.com/scgolang/osc/blob/master/argument.go#L239

Bytes method of String calls ToBytes. ToBytes returns []byte{} when len(string) == 0
https://github.com/scgolang/osc/blob/master/osc.go#L46

Then Pad doesn't append any null character (it isn't called)
https://github.com/scgolang/osc/blob/master/osc.go#L55

ToBytes is also used for msg.Address and BundleTag :
https://github.com/scgolang/osc/blob/master/message.go#L54
https://github.com/scgolang/osc/blob/master/bundle.go#L79

Both can't be empty according to the OSC specs I think*.

And a empty string is tested:
https://github.com/scgolang/osc/blob/master/osc_test.go#L14
It expects: []byte{}
but in this case it should be the following I think:
[]byte{0,0,0,0}

From the specs: osc string = A sequence of non-null ASCII characters followed by a null, followed by 0-3 additional null characters

(
Not related to this issue I think, but ReadString has a similar way of handling empty strings
https://github.com/scgolang/osc/blob/master/osc.go#L71
)

Looking at the gosc library, it checks if a string has "\x00" as suffix and adds it when it doesn't have any, as is the case with a empty string.
https://github.com/loffa/gosc/blob/master/writer.go#L104

I think something similar is done in the go-osc library:
https://github.com/hypebeast/go-osc/blob/master/osc/osc.go#L1027

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants