aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-03-02 10:17:58 -0600
committerRob Landley <rob@landley.net>2020-03-02 10:17:58 -0600
commit75ad10ea53073a2dc90808a36db2fcd5107909ce (patch)
treea581ed9f5e523071674af554e7a957f103021f76 /toys
parente8705902647ae62bdf3c7605d76be725ef385a63 (diff)
downloadtoybox-75ad10ea53073a2dc90808a36db2fcd5107909ce.tar.gz
Work around gcc trying to be "helpful" again.
Diffstat (limited to 'toys')
-rw-r--r--toys/lsb/md5sum.c7
1 files 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<sizeof(TT)-((unsigned long)TT.state-(unsigned long)&TT); pp++)
+ *pp = 0;
i = strlen(toybuf)+1;
memset(toybuf+i, 0, sizeof(toybuf)-i);
}