cancel
Showing results for 
Search instead for 
Did you mean: 

Writting text with Unicode::fromUTF8 bug

AAlis.23
Associate III

Hi,

I haver two text areas AAA and BBB both with wildcard buffer to write to. When use the funcion Unicode::fromUTF8 to write some text and the text is larger than the buffer the values of the two text areas are concatenated and writted on the first area.

If title lenght is larger than text area buffer the two buffers are concatenated and pinted in the fist text area:

Unicode::fromUTF8((const uint8_t*)title, AAABuffer, AAA_SIZE);

Unicode::fromUTF8((const uint8_t*)title2, BBBBuffer, BBB_SIZE);

The solucion is to limit the size to one less:

Unicode::fromUTF8((const uint8_t*)title, AAABuffer, AAA_SIZE - 1);

Unicode::fromUTF8((const uint8_t*)title2, BBBBuffer, BBB_SIZE - 1);

I think this is a small bug and the compiler must limit it.

Thanks

11 REPLIES 11
Piranha
Chief II

@Yoann KLEIN​ , as @t.decker​ explained, not setting the terminating null character is a bug of the fromUTF8() function/method.

> Unfortunately some standard c-lib function have the same behaviour, so this might be intentended?

The strncpy() is not really a function for copying strings. It is meant for filling a character arrays with a text from a string. Despite a confusing documentation, it actually does not null terminate strings at all, but instead fills the rest of the array with null characters. Obviously, if there is no space left, it does nothing.

Hi,

For me this is a bug, this funcion should crop the text to avoid concatenation of strings, not responsibility of the user to ba safe that the text is MAXCHARS-1.

Thanks