minetest/irrlicht

-Wtype-limits warnings in irrUString.h

Desour opened this issue · 5 comments

I'm getting -Wtype-limits warnings in these lines:

else if (c2[l] == 0xC0 || c2[l] == 0xC1)

if (c2[l] > 0x7F)

If you cast a signed char (to compare), it's some negative number, and the comparison is always false.

Other lines may also be affected, i.e. wrong shifting.

I guess #33 introduced this. (cc @numberZero @sfan5)

Maybe using u8 instead of char would be better. But idk, hence this issue.

In the calculations, it has to be u8 (or char8_t but that’s C++20). But the API has to accept char *. So, cast. I think it is OK to cast pointers and not values (unsigned char is allowed to alias anything, and u8 is unsigned char).

Is ustring16 used anywhere actually? My grep suggests it isn’t.

Yes.

typedef ustring16 ustring;

mtsrc/irrlicht_changes/CGUITTFont.h and mtsrc/irrlicht_changes/CGUITTFont.cpp use ustring.

But the function (ustring16::append(const uchar8_t* const, u32)) isn't called anywhere.
So, we could just remove the function to suppress the warning. However, appending a utf8 string could be useful.
Also, other code using uchar8_t could be bugged.

The easiest way to see if a function is used in C++ is to comment it out (surround with #if 0/#endif) and do a clean build.
The append function that has the compile warning is not used.