lib:util: Fix printing hex‐escaped characters
authorJo Sutton <josutton@catalyst.net.nz>
Tue, 20 Feb 2024 03:35:43 +0000 (16:35 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 27 Feb 2024 01:11:37 +0000 (01:11 +0000)
commit3b85345c4c5bc7fa7196c8802a6be60e0e4a043f
treeea4e656f9e0603bcd1eab3fac7790cf9fbc06468
parent7e855f8d89cb0b3491d31c93da608417c38c6b00
lib:util: Fix printing hex‐escaped characters

A signed char, passed to snprintf(), will be promoted to an ‘int’, and
then interpreted (according to the format string) as an ‘unsigned int’.
Any negative values passed in will thus be interpreted as large unsigned
values, too large to be represented in the two characters allocated for
them. In practice, they will always be represented as ‘\xFF’.

Cast these characters to ‘unsigned char’, and use the appropriate length
modifier for that type.

Signed-off-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/util/util_str_escape.c