Fix JsonString operator == and != for non-zero-terminated string

This commit is contained in:
Benoit Blanchon
2022-02-17 11:16:05 +01:00
parent a880614a75
commit f831ed395d
3 changed files with 30 additions and 22 deletions

View File

@ -46,23 +46,19 @@ class String : public SafeBoolIdom<String> {
}
friend bool operator==(String lhs, String rhs) {
if (lhs._size != rhs._size)
return false;
if (lhs._data == rhs._data)
return true;
if (!lhs._data)
return false;
if (!rhs._data)
return false;
return strcmp(lhs._data, rhs._data) == 0;
return memcmp(lhs._data, rhs._data, lhs._size) == 0;
}
friend bool operator!=(String lhs, String rhs) {
if (lhs._data == rhs._data)
return false;
if (!lhs._data)
return true;
if (!rhs._data)
return true;
return strcmp(lhs._data, rhs._data) != 0;
return !(lhs == rhs);
}
#if ARDUINOJSON_ENABLE_STD_STREAM