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

Unclear code fragment in rfm_filop_write() #20

Open
nxdefiant opened this issue Mar 12, 2016 · 0 comments
Open

Unclear code fragment in rfm_filop_write() #20

nxdefiant opened this issue Mar 12, 2016 · 0 comments

Comments

@nxdefiant
Copy link

In rfm_filop_write() you are using this code fragment to increment the out_cur_end pointer to the end of the current buffer:

*rfm12->out_cur_end++ = 0;         // hdr
*rfm12->out_cur_end++ = (u8)copied;   // len
rfm_apply_crc16(rfm12, rfm12->out_cur_end-2, copied+offset);
rfm12->out_cur_end += copied + offset;

which is a bit confusing for me. If I understand this correctly the pointer increment in the first 2 lines actually does increment the pointer for the crc at this place, not the header (which is also 2 bytes), because the length of the header is already accumulated in offset.

recommended rewrite:

*rfm12->out_cur_end = 0;
*(rfm12->out_cur_end+1) = (u8)copied
rfm_apply_crc16(rfm12, rfm12->out_cur_end, copied+offset);
rfm12->out_cur_end += copied + offset + 2; // +2 byte crc

I stumbled about this when attempting to use your code with a protocol that does not know the first header byte, after a few modifications it works, thanks for sharing the code.

Also please use constants for header and crc length instead of using the value 2 for both. Sometimes it is a bit hard to spot which is which.

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

No branches or pull requests

1 participant