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

asciitohex adjust to end string correctly #18

Open
jps1x2 opened this issue Nov 22, 2023 · 2 comments
Open

asciitohex adjust to end string correctly #18

jps1x2 opened this issue Nov 22, 2023 · 2 comments

Comments

@jps1x2
Copy link

jps1x2 commented Nov 22, 2023

HI mcore1976!

Function asciitohex is finishing string 2 chars after last written hex value. I am playing with your code and making some adjustements.

File: cc1101-tool-esp32-wroom.ino
Line: 103 hex_ptr[(2*i)+2] = '\0' ;
Correction: hex_ptr[(2*i)] = '\0' ;

Reason: variable i exits incremented from previous for bucle.
When code reaches line 103, i variable has the needed value to finish string fine adding \0, it is not needed to add 2 more char positions to it.

Regards!

Jps1x2

@mcore1976
Copy link
Owner

I did not test it but I used this line 103 to put NULL into the string (array of chars) just in case

@naldoxable
Copy link

I can confirm that the correction is safe.

A similar situation arises in the last line of hextoascii:
ascii_ptr[i++] = '\0';
can be modified to:
ascii_ptr[i] = '\0';

The case I mentioned is more of a formality, while the solution for the asciitohex function is an improvement as it prevents the addition of a blank space.

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

3 participants