avoid even the chance at UB, it’s too risky with “postmodern” compilers
This commit is contained in:
		
							
								
								
									
										6
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								main.c
									
									
									
									
									
								
							@@ -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
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								var.c
									
									
									
									
									
								
							@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user