telx: fix truncation warning
Fix the -Wstringop-truncation warning by setting a correct size to the line being read:
../../modules/codec/telx.c: In function ‘Decode’:
../../modules/codec/telx.c:583:9: warning: ‘__builtin_strncpy’ output may be truncated copying 127 bytes from a string of length 255 [-Wstringop-truncation]
583 | strncpy( p_sys->ppsz_lines[0], psz_line,
| ^
../../modules/codec/telx.c:535:9: warning: ‘__builtin_strncpy’ output may be truncated copying 127 bytes from a string of length 255 [-Wstringop-truncation]
535 | strncpy( p_sys->ppsz_lines[row], t,
| ^
../../modules/codec/telx.c:501:9: warning: ‘__builtin_strncpy’ output may be truncated copying 127 bytes from a string of length 255 [-Wstringop-truncation]
501 | strncpy( p_sys->ppsz_lines[0], psz_line,
| ^
Since at most len
characters are read from the input, and an utf-8
caracter is written in the output for each character from the input,
and since the to_utf8 function only supports utf-8 characters with at
most 3 characters, then it's not possible to write more than 3 times len
into the output buffer, without accounting the terminating character.
Additional related changes are made to:
-
Move the creation of psz_line close to decode_string, since that's the main first user and it needs the size of the buffer, helping readability.
-
Add assertion checking that we don't extend utf-8 to 4 bytes, which is mainly for development, since the function will not outreach the bounds of psz_line anyway.
-
Add some documentation for
decode_string
so it's clearer how the length of the buffer should be assigned.