]> git.ozlabs.org Git - ccan/commit
hex: Simplify hex_encode
authorJon Griffiths <jon_p_griffiths@yahoo.com>
Mon, 30 May 2016 12:39:10 +0000 (00:39 +1200)
committerJon Griffiths <jon_p_griffiths@yahoo.com>
Mon, 22 Aug 2016 12:33:41 +0000 (00:33 +1200)
commit578c4bfb22dd2df3c8133066b28397725b76734a
tree084ec25f5707e46c8d6d6dcc5c5798be947769a7
parentbe24e496578d7c03bc2fd6239887266e82c8d6da
hex: Simplify hex_encode

The documentation for hex_encode indicates that it returns simply true or
false. The old implementation was returning the written length on success,
cast to boolean. This will elicit a warning under MSVC.

On further examination, there is no need to check/modify the length inside
the loop, since we can check it once before starting. As a result the code
can be simplified a bit.

A side affect of this change is that nothing will be written at all if the
length is incorrect, vs the previous code writing characters until the length
available is exhausted. I prefer the new semantics but YMMV.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
ccan/str/hex/hex.c