-
Notifications
You must be signed in to change notification settings - Fork 939
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
SmsDetector doesnt check how many bytes where read from input #615
Comments
Forgive me if I wrong but the bytes from this dis.read(b); are stored in the b array and then this is turned into a string as you can see in the next few lines? This string is then split by \n and sent to the sms detection function as an array of strings. The dis isn't read if it has 0 bytes bufferlen != 0, I should have changed this to > 0 to avoid -1 values. but this data is being used. |
bufferlen = dis.available(); this is telling how many bytes are available in the stream to read also. |
It tells you how many bytes are(were) available, but not how many bytes were read,
|
also, you just found another serious, difficult to reproduce bug with
|
Whats the best solution to the problem then ali because so far its working for me continuously on 3 different model phones and doesn't miss an sms being sent? |
Ignore bufferlength size and check |
Only put sleep to slow things down to save cpu usage and give buffer or stream time to fill up instead of continuously reading ever nano second |
Ymm ok, so I guess this could be changed to I mean, this might not work as you think it works(?)
it constructs new thread, makes it wait 500 before not doing anything else to the thread so it dies in GC. |
@banjaxbanto: have you tested @Agilop's proposal? |
I believe, if the read method returned value is used instead of available(), it would block until the data is available, so there would be no need for Thread.sleep call to save CPU. |
Thanks for your endurance with our shitty bugs, @banjaxbanjo. I am currently cleaning up. Stay tight! |
You're reading data from
dis
and doing nothing with it. It looks like you should do something with the input and this introduces a potential and very difficult to reproduce bug.You cannot assume that any given stream reading call will fill the byte[] passed in to the method. Instead, you must check the value returned by the read method to see how many bytes were read.
The text was updated successfully, but these errors were encountered: