Open
Description
ArduinoCore-API/api/String.cpp
Line 445 in 7f8de58
ArduinoCore-API/api/String.cpp
Line 445 in 7f8de58
memcmp()
to make sure that a String object can be compared to another String object that has embedded NUL
charactersArduinoCore-API/api/String.cpp
Line 445 in 7f8de58
ArduinoCore-API/api/String.cpp
Line 445 in 7f8de58
memcmp()
to make sure that a String object can be compared to another String object that has embedded NUL
characters
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::equalsIgnoreCase
implies 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
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 toString
in the past suggest that this is not the intention, and the goal is to makeString
work even with embedded nuls.cvwillegen commentedon May 4, 2022
memcmp
is a standard function in the C library...