$darkmode
Elektra 0.11.0
|
When using keyString() on empty / binary values the return values are the literal strings (null) / (binary). This seems very awkward and unintuitive from a user's perspective.
Because the return value of the function is const char*
, there are not so many possibilities for a change to this behavior, as every possible return value - except for a NULL pointer - could just be the value of the string of the Key.
On one hand always returning a string allows things like strlen(keyString(k)) == 0
to check for an empty string. But at the same time people might expect that strlen(keyString(k)) < MAX_LEN
also works. But this again might silently break code down the line, if k
is binary and strlen("(binary)") < MAX_LEN
.
An alternative would be to always store a zero byte after all key values, even if they are binary (might be done already). Then we can safely return k->data.c == NULL ? "" : k->data.c
. It may contain incomplete data and the MAX_LEN
problem from above still applies, but there are no segfaults and you don't get return values that have nothing to do with the actual data.
key == NULL
return 0, error code via second channelkey->value == NULL
return 0, error code via second channelkey == <binary>
return 0, error code via second channel