avoid even the chance at UB, it’s too risky with “postmodern” compilers

This commit is contained in:
tg 2016-10-22 23:56:50 +00:00
parent 56bdf24e54
commit ac405dd6b7
2 changed files with 4 additions and 8 deletions

6
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.318 2016/09/01 12:59:10 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.319 2016/10/22 23:56:50 tg Exp $");
extern char **environ;
@ -111,10 +111,8 @@ rndsetup(void)
char *cp;
cp = alloc(sizeof(*bufptr) - sizeof(ALLOC_ITEM), APERM);
#ifdef DEBUG
/* clear the allocated space, for valgrind */
/* clear the allocated space, for valgrind and to avoid UB */
memset(cp, 0, sizeof(*bufptr) - sizeof(ALLOC_ITEM));
#endif
/* undo what alloc() did to the malloc result address */
bufptr = (void *)(cp - sizeof(ALLOC_ITEM));
/* PIE or something similar provides us with deltas here */

6
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.207 2016/08/01 21:38:07 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.208 2016/10/22 23:56:50 tg Exp $");
/*-
* Variables
@ -1686,10 +1686,8 @@ rndset(unsigned long v)
short r;
} z;
#ifdef DEBUG
/* clear the allocated space, for valgrind */
/* clear the allocated space, for valgrind and to avoid UB */
memset(&z, 0, sizeof(z));
#endif
h = lcg_state;
BAFHFinish_reg(h);