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

SDLV1/V2ProtocolHeader objects are not properly converted to byte data #84

Closed
jacobkeeler opened this issue Feb 17, 2015 · 0 comments
Closed
Labels
bug A defect in the library

Comments

@jacobkeeler
Copy link

There is a very subtle bug in the data function for SDLV1ProtocolHeader and SDLV2ProtocolHeader:

Byte compressed = self.compressed?1:0 << 3; // next 1 bit

Because there are no parentheses around self.compressed?1:0, the bit shift is not evaluated on the result, but the 0.

An equivalent if statement to this conditional would be:

Byte compressed;
if (self.compressed) {
    compressed = 1;
}
else {
    compressed = 0 << 3;
}

Rather than the intended behavior:

Byte compressed;
if (self.compressed) {
    compressed = 1 << 3;
}
else {
    compressed = 0 << 3;
}

As a result, the compressed flag can never be set. In addition, if the variable is set to YES, the value will interfere with the frameType section of the header.

This can easily be fixed, the line could simply be changed to:

Byte compressed = (self.compressed?1:0) << 3; // next 1 bit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A defect in the library
Projects
None yet
Development

No branches or pull requests

2 participants