bugfix in rich unpacker
This MR fixes a bug in RICH unpacker, that is shown by the following compiler warnings:
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx: In function 'std::__cxx11::string mRichSupport::GetWordHexRepr(const uint8_t*)':
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx:69:32: warning: 'snprintf' output truncated before the last format character [-Wformat-truncation=]
snprintf(cStr, buf_size - 1, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
^~~~~~~~~~~~~~~~~~~
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx:69:11: note: 'snprintf' output 10 bytes into a destination of size 9
snprintf(cStr, buf_size - 1, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx: In function 'std::__cxx11::string mRichSupport::GetBinaryRepresentation(size_t, const uint8_t*)':
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx:23:36: warning: 'snprintf' output truncated before the last format character [-Wformat-truncation=]
snprintf(cStr, buf_size - 1, "%u", byte);
^~~~
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx:23:15: note: 'snprintf' output 2 bytes into a destination of size 1
snprintf(cStr, buf_size - 1, "%u", byte);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx: In function 'std::__cxx11::string mRichSupport::GetHexRepresentation(size_t, const uint8_t*)':
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx:47:34: warning: 'snprintf' output truncated before the last format character [-Wformat-truncation=]
snprintf(cStr, buf_size - 1, "%02x", byte);
^~~~~~
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx:47:13: note: 'snprintf' output 3 bytes into a destination of size 2
snprintf(cStr, buf_size - 1, "%02x", byte);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx: In function 'std::__cxx11::string mRichSupport::GetWordHexReprInv(const uint8_t*)':
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx:91:32: warning: 'snprintf' output truncated before the last format character [-Wformat-truncation=]
snprintf(cStr, buf_size - 1, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
^~~~~~~~~~~~~~~~~~~
/home/cbmdock/cbmroot/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx:91:11: note: 'snprintf' output 10 bytes into a destination of size 9
snprintf(cStr, buf_size - 1, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The code above assumes that the second snprintf() parameter, "maximal length", is the maximal number of characters one can put in the buffer (which is the buffer length minus 1). But snprintf() considers the second parameter as the full length of the buffer (including the last '\0').
Therefore in all the snprintf() calls above, all the messages are truncated.
I don't know how these messages are used, i.e., if my bugfix changes the results or if it only changes some log output.