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

[Possible PR] Fix to_hstring to stop it from using a negative index. #16

Open
Trikzon opened this issue Apr 27, 2021 · 0 comments
Open

Comments

@Trikzon
Copy link

Trikzon commented Apr 27, 2021

In cstr.cpp inside of the for loop you index your hexTo_StringOutput with a negative index when i goes past 7.

This can be fixed like so:

char hexTo_StringOutput[128];
const char* to_hstring(uint64_t value){
    uint64_t* valPtr = &value;
    uint8_t* ptr;
    uint8_t tmp;
    uint8_t size = 8 * 2 - 1;
-   for (uint8_t i = 0; i < size; i++){
+   for (uint8_t i = 0; i < size / 2 + 1; i++){
        ptr = ((uint8_t*)valPtr + i);
        tmp = ((*ptr & 0xF0) >> 4);
        hexTo_StringOutput[size - (i * 2 + 1)] = tmp + (tmp > 9 ? 55 : '0');
        tmp = ((*ptr & 0x0F));
        hexTo_StringOutput[size - (i * 2)] = tmp + (tmp > 9 ? 55 : '0');
    }
    hexTo_StringOutput[size + 1] = 0;
    return hexTo_StringOutput;
}

I am willing to pr this change if you want, but I'm not sure if you want it to be pulled into all branches since episode 4 or not.

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