On Mon, Mar 29, 2021 at 12:42:02PM +0200, Theo Buehler wrote: > On Mon, Mar 29, 2021 at 10:38:54AM +0200, Claudio Jeker wrote: > > Replace a super strange way to translate some binary blob into a hex string. > > The code drops the : from the string but this is fine, the : is just > > visual fluff. I used the same function in the not yet finished RRDP > > codebase and there I don't want the extra ':'. > > Yes, that's much better. > > Another detail that changes is that the hexadecimal digits will now be > lower case. Trading one byte overallocation for a free overflow check > is reasonable. The explicit NUL termination out[i * 2] = '\0' is not > really needed since we calloc, but it's probably fine to be explicit.
Yeah, I decided to overallocate by one but have calloc() do the overflow check. Also I flipped to uppercase hex since both Job and you mentioned it. I just prefer the explicit NUL termination, if someone copy pastes the code somewhere else where no calloc() happens then such an implicit side-effect could introduce a bug. > ok tb > > for the diff as it is (also for moving the function to x509.c) I also renamed the function to hex_encode() so it fits with base64_decode() which sits in tal.c. I consider to move those functions plus a soon needed hex_decode() into a new file (encoding.c). -- :wq Claudio