I recently discovered when parsing a hex string with 5 characters (0x10001) that loadFromHexString
sets the required size of the internal data incorrectly.
ensureSize ((size_t) hex.length() >> 1);
This line only works correctly when hex.length()
is a multiple of 2.
Suggested fix:
insert a jassert(hex.length() % 2 == 0);
at the top of the function and a comment explaining that strings passed into this function should have a length which is a multiple of 2.
I’m currently doing the following as a workaround where I’m using loadFromHexString()
:
/*
loadFromHexString() expects the string to have a length that is a multiple of 2.
This is not stated in the documentation, but the implementation reveals this.
*/
if( hex.length() % 2 != 0 )
{
hex = "0" + hex;
}
bytes.loadFromHexString(hex);