Bug #2077

Updated by Zbigniew Rebacz over 3 years ago

Here is the warnings generated by gcc on Linux:
<pre>
/home/klugier/upp/uppsrc/Core/AString.hpp: In member function ‘void Ide::ResolveUvsConflict()’:
/home/klugier/upp/uppsrc/Core/AString.hpp:269:36: warning: ‘int __builtin_memcmp_eq(const void*, const void*, long unsigned int)’ reading 17 bytes from a region of size 16 [-Wstringop-overflow=]
269 | return len == GetCount() && memcmp(begin(), s, len) == 0; // compiler is happy to optimize memcmp out...
| ~~~~~~^~~~~~~~~~~~~~~~~
/home/klugier/upp/uppsrc/Core/AString.hpp:269:36: warning: ‘int __builtin_memcmp_eq(const void*, const void*, long unsigned int)’ reading 17 bytes from a region of size 16 [-Wstringop-overflow=]
269 | return len == GetCount() && memcmp(begin(), s, len) == 0; // compiler is happy to optimize memcmp out...
| ~~~~~~^~~~~~~~~~~~~~~~~
/home/klugier/upp/uppsrc/Core/AString.hpp:269:36: warning: ‘int __builtin_memcmp_eq(const void*, const void*, long unsigned int)’ reading 21 bytes from a region of size 16 [-Wstringop-overflow=]
269 | return len == GetCount() && memcmp(begin(), s, len) == 0; // compiler is happy to optimize memcmp out...
|
</pre>

Solution that fix the warning (not sure about performance):
<pre>
inline
bool String0::IsEqual(const char *s) const
{ // This optimized for comparison with string literals...
size_t len = strlen(s);
return len == GetCount() && strncmp(begin(), s, len) == 0;
}
</pre>

Tested on GCC 10.2.

Back