From 75ad10ea53073a2dc90808a36db2fcd5107909ce Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 2 Mar 2020 10:17:58 -0600 Subject: Work around gcc trying to be "helpful" again. --- toys/lsb/md5sum.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/toys/lsb/md5sum.c b/toys/lsb/md5sum.c index ff7e8b45..31770ed5 100644 --- a/toys/lsb/md5sum.c +++ b/toys/lsb/md5sum.c @@ -288,7 +288,7 @@ static void do_builtin_hash(int fd, char *name) { uint64_t count; int i, sha1=toys.which->name[0]=='s'; - char buf; + char buf, *pp; void (*transform)(void); /* SHA1 initialization constants (md5sum uses first 4) */ @@ -329,7 +329,10 @@ static void do_builtin_hash(int fd, char *name) else for (i=0; i<4; i++) sprintf(toybuf+8*i, "%08x", bswap_32(TT.state[i])); // Wipe variables. Cryptographer paranoia. - memset(TT.state, 0, sizeof(TT)-((long)TT.state-(long)&TT)); + // if we do this with memset(), gcc throws a broken warning, and the (long) + // typecasts stop gcc from breaking "undefined behavior" that isn't. + for (pp = (void *)TT.state; (unsigned long)pp-(unsigned long)TT.state