I suggest looking at how gnulib does it. It's had a fix for this for some time. It might help to compare notes. http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/md5.c and similarly for sha256.c, sha512.c. The md5 fix, at least, is a bit more readable and avoids the need for additional functions.