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
Unlike C-style strings, std::strings can contain the null character. For example std::string("hello\0world").
However, in BLERemoteCharacteristic.cpp, the std::string newValue is converted to a C-style string before being sent to writeValue. This means that any characters after a null character in newValue will not be sent to writeValue. For example, std::string("hello\0world") will be converted into the C-style/null-terminated string "hello\0".
A fix would be to use the data() method on std::string and, more importantly, the length() method on std::string. newValue.length() will give the total length of the string (including any null characters), however strlen will only return the length up to the first null character.
@chegewara, I'm not sure I understand your comment. Are you suggesting I not use writeValue(std::string newValue, bool response = false) in cases where newValue may contain null characters?
Unlike C-style strings,
std::string
s can contain thenull
character. For examplestd::string("hello\0world")
.However, in BLERemoteCharacteristic.cpp, the
std::string newValue
is converted to a C-style string before being sent to writeValue. This means that any characters after a null character innewValue
will not be sent towriteValue
. For example,std::string("hello\0world")
will be converted into the C-style/null-terminated string"hello\0"
.arduino-esp32/libraries/BLE/src/BLERemoteCharacteristic.cpp
Line 538 in f7fb006
A fix would be to use the
data()
method onstd::string
and, more importantly, thelength()
method onstd::string
.newValue.length()
will give the total length of the string (including any null characters), howeverstrlen
will only return the length up to the first null character.The text was updated successfully, but these errors were encountered: