Bug Hunting Adventures #15: Hex String Entanglements

“Don’t be drawn into any web of entanglement created by others.”
― Steven Redhead, Life Is Simply A Game

The following routine is from a real-world project. It’s supposed to convert binary data into a printable C-string of hexadecimal digits. Even though the developer diligently wrote some unit tests, he got complaints from his fellow coders a few days later. Can you find what’s wrong with it?

Unit tests:

Solution

Comments (2)

  1. 13:48, 19-12-2020Ralph Doncaster (Nerd Ralph)  / Reply

    I see another bug. to_hexstring() doesn’t make sure *out == ‘\0’.

    • 14:37, 19-12-2020Ralf  / Reply

      Can you provide a test case?

Leave a Reply