Casting to unsigned char is good to do (pushed a patch for it), but snprintf() is not writing if it needs more space than the buffer size parameter (6 in this case) -- that's the reason the log message is printed. So there has to be something else.
Did you get a core dump file? If yes, can you grab the backtrace with gdb and paste it here?