You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
String == String does not work with embedded NUL characters #112
Yes, I saw your pull request (and commented on it). As far as I can see, it
still has strcmp() calls in it... please correct me if I'm wrong!
Christ van Willegen
@cvwillegen, seems you're right, I should probaly dust off that PR sometime and also fix those calls...
@prath06, but it seems that stricmp() just makes the comparison case insensitive, and also it does not seem to be a standard libc function at all. How would this help here?
In C, C strings are just an array of chars terminated by NULL. That is how strcmp(), strcpy(), etc know where the end of the string is. The Arduino String class does a nice job hiding those implementation details, but the fact remains: embedded nulls in Strings WILL BREAK THINGS.
In C, C strings are just an array of chars terminated by NULL.
Sure, that's how C strings work. But the String class is something different - it's a buffer with an explicit length, so there is no reason why embedded nuls could not be supported by it.
Sure, we could define this as an (artificial) limitation on the String class as well, which could make its implementation simpler (because it can then just use the C-string functions for its processing without any extra work), but changes made to String in the past suggest that this is not the intention, and the goal is to make String work even with embedded nuls.
Activity
cvwillegen commentedon Apr 18, 2020
Also,
ArduinoCore-API/api/String.cpp
Line 467 in 7f8de58
ArduinoCore-API/api/String.cpp
Line 492 in 7f8de58
ArduinoCore-API/api/String.cpp
Line 498 in 7f8de58
You can debate if there is a change needed to
ArduinoCore-API/api/String.cpp
Line 470 in 7f8de58
String::equalsIgnoreCaseimplies only printable characters.matthijskooijman commentedon Apr 21, 2020
Did you see #97? It is related and I think it might solve your issue (but it's been too long since I wrote it, so I cannot recall exactly).
cvwillegen commentedon Apr 21, 2020
prath06 commentedon Nov 3, 2020
Instead of strcmp(), try using stricmp(). It may work
matthijskooijman commentedon Nov 4, 2020
@cvwillegen, seems you're right, I should probaly dust off that PR sometime and also fix those calls...
@prath06, but it seems that
stricmp()just makes the comparison case insensitive, and also it does not seem to be a standard libc function at all. How would this help here?mrengineer7777 commentedon May 4, 2022
In C, C strings are just an array of chars terminated by NULL. That is how strcmp(), strcpy(), etc know where the end of the string is. The Arduino String class does a nice job hiding those implementation details, but the fact remains: embedded nulls in Strings WILL BREAK THINGS.
matthijskooijman commentedon May 4, 2022
Sure, that's how C strings work. But the
Stringclass is something different - it's a buffer with an explicit length, so there is no reason why embedded nuls could not be supported by it.Sure, we could define this as an (artificial) limitation on the
Stringclass as well, which could make its implementation simpler (because it can then just use the C-string functions for its processing without any extra work), but changes made toStringin the past suggest that this is not the intention, and the goal is to makeStringwork even with embedded nuls.cvwillegen commentedon May 4, 2022
memcmpis a standard function in the C library...fix(String): compare embedded NUL bytes correctly