mlabbe / nativefiledialog

A tiny, neat C library that portably invokes native file open and save dialogs.
zlib License
1.76k stars 209 forks source link

Problem with NFDi_UTF8_Strlen and char #80

Closed dmaluev closed 3 years ago

dmaluev commented 4 years ago

This code will not work properly: else if (str[i] >> 6 == 2) because for non-ascii char the value will actually be negative. For bitshift operation char will be promoted to negative int with all 3 upper bytes having all their bits set to 1. So the result will be some large value, not 2. This code will work: else if (((str[i] >> 6) & 0x3) == 2) Bit mask is your friend ;)

mlabbe commented 3 years ago

Resolved, thanks