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

array index bound exception #15

Closed
francescoc93 opened this issue Dec 10, 2016 · 5 comments
Closed

array index bound exception #15

francescoc93 opened this issue Dec 10, 2016 · 5 comments
Labels

Comments

@francescoc93
Copy link

There's a numerical overflow in "ask" method of FirmataI2CDevice class. The type byte in Java is signed. So, when the AtomicInteger return a value greater than 127, the value of variable "reg" is negative, and that, provoke an array index bound exception

@kurbatov
Copy link
Owner

I have commited the fix for that. Could you please confirm if it works now?

@francescoc93
Copy link
Author

francescoc93 commented Dec 10, 2016

now doesn't provoke an exception, but i can't get the response from the device when the index of array is greater than 127

@kurbatov kurbatov reopened this Dec 10, 2016
@francescoc93
Copy link
Author

a workaround may be to set the size of the array to 128. The instruction register.compareAndSet(256, 1) will become register.compareAndSet(128, 1)

@kurbatov
Copy link
Owner

Unfortunately I haven't managed to reproduce the issue.

Another way around this bug is subscribing a listener and receiving updates continously. This way you don't have to invoke ask method all the time.

    i2cDevice.subscribe(new I2CListener() {...});
    i2cDevice.startReceivingUpdates(messageLength);

@kurbatov
Copy link
Owner

kurbatov commented Jun 8, 2017

Register type was promoted from byte to int in 2.3.5 and it fixes described bug.

@kurbatov kurbatov closed this as completed Jun 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants