-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Avoid copying null in concat, unused + breaks views #8198
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good corner case find!
Can you please add a unit test in tests/host./core/test_string.cpp?
I'm not able to reproduce this anymore, maybe it was a misdiagnose of mine, it was late and I was tired and I ended up fixing a few other bugs in our code simultaneously. I probably stumbled on it by accident and thought the correlation was causality to my crashes. But I may have indeed reached an edge case that cause a problem because we do not put the stack in the 4kb unused sys stack. So we have a few std::arrays stored in its place, and the one that seemed to trigger the problem was the last one. But it doesn't get to 0x4000000, not even the full 4096 bytes to 0x3FFFF000. So where should memove_P break with a off by one bug like this one? I've spent quite some time to find a reproducible example but failed. Do you have a suggestion? Sorry for crying wolf (crash) without being sure. |
Sorry, I don't have any suggestions. I don't see how the existing code could cause a crash, which is why I was hoping to see an example that fails on the 3.0.1 release but passes with this PR. That said, I think this PR is correct, though, and current code is reading 1 byte past where it should (the 0-termination is added 2 lines after the memcpy no matter what, no need to memcpy it). Using host tests lets us use |
Nice, so something like this would solve the problem? void setup() {
char ch = 'A';
String str;
str.concat(&ch, 1);
} |
More like this...
Which generates an error in valgrind on host tests
|
Done. Thank you for the help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now, thanks!
@paulocsanz please add a |
We use a few non-null terminated views and it seems String::concat(char*, size_t) breaks those because it always copies the null terminator, but since the function immediately overwrites it, it doesn't need to.
This change makes String::concat support non-null terminated char* without any side effect.
Fixes #8200