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

Do not pass empty frameBytes #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TehDmitry
Copy link

No description provided.

@bvernoux
Copy link

bvernoux commented Mar 14, 2018

I have done an other variant of this fix by adding a check on frame f before to call DeviceManager.giveFrame(f); and also check frameBytes.size() > 0 to avoid some exception in some cases
See my proposal for your updated patch:

@@ -175,8 +175,20 @@ public class CantactDevice {
                     for (byte b : bs) {
                         if (b == '\r') {
                             // end of frame data received
-                            CanFrame f = slcanToFrame(frameBytes.toArray(new Byte[frameBytes.size()]));
-                            DeviceManager.giveFrame(f);
+                            CanFrame f;
+                            if(frameBytes.size() > 0)
+                            {
+                                f = slcanToFrame(frameBytes.toArray(new Byte[frameBytes.size()]));
+                                if(f != null)
+                                    DeviceManager.giveFrame(f);
+                            }
+                            if(frameBytes.size() > 4)
+                            {
+                                // end of frame data received
+                                f = slcanToFrame(frameBytes.toArray(new Byte[frameBytes.size()]));
+                                if(f != null)
+                                    DeviceManager.giveFrame(f);
+                            }
                             frameBytes.clear();
                         } else {
                             // byte received, add to buffer

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 this pull request may close these issues.

2 participants