fix some of the things scan-build[1] found (but not some false positives)
10x From: Elias Pipping <elias@pipping.org> [1] http://clang.llvm.org/StaticAnalysis.html
This commit is contained in:
		
							
								
								
									
										4
									
								
								check.t
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								check.t
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| # $MirOS: src/bin/mksh/check.t,v 1.229 2008/10/10 21:30:41 tg Exp $ | # $MirOS: src/bin/mksh/check.t,v 1.230 2008/10/13 23:06:01 tg Exp $ | ||||||
| # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ | # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ | ||||||
| # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ | # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ | ||||||
| # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ | # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ | ||||||
| @@ -7,7 +7,7 @@ | |||||||
| # http://www.research.att.com/~gsf/public/ifs.sh | # http://www.research.att.com/~gsf/public/ifs.sh | ||||||
|  |  | ||||||
| expected-stdout: | expected-stdout: | ||||||
| 	@(#)MIRBSD KSH R35 2008/10/10 | 	@(#)MIRBSD KSH R35 2008/10/13 | ||||||
| description: | description: | ||||||
| 	Check version of shell. | 	Check version of shell. | ||||||
| stdin: | stdin: | ||||||
|   | |||||||
							
								
								
									
										7
									
								
								edit.c
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								edit.c
									
									
									
									
									
								
							| @@ -5,7 +5,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #include "sh.h" | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.137 2008/10/05 16:06:43 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.138 2008/10/13 23:06:02 tg Exp $"); | ||||||
|  |  | ||||||
| /* tty driver characters we are interested in */ | /* tty driver characters we are interested in */ | ||||||
| typedef struct { | typedef struct { | ||||||
| @@ -1517,7 +1517,7 @@ x_emacs(char *buf, size_t len) | |||||||
| 		} | 		} | ||||||
| 		i = c | (x_curprefix << 8); | 		i = c | (x_curprefix << 8); | ||||||
| 		x_curprefix = 0; | 		x_curprefix = 0; | ||||||
| 		switch (i = (*x_ftab[f].xf_func)(i)) { | 		switch ((*x_ftab[f].xf_func)(i)) { | ||||||
| 		case KSTD: | 		case KSTD: | ||||||
| 			if (!(x_ftab[f].xf_flags & XF_PREFIX)) | 			if (!(x_ftab[f].xf_flags & XF_PREFIX)) | ||||||
| 				x_last_command = f; | 				x_last_command = f; | ||||||
| @@ -1727,7 +1727,6 @@ x_delete(int nc, int push) | |||||||
| 		x_push(nb); | 		x_push(nb); | ||||||
|  |  | ||||||
| 	xep -= nb; | 	xep -= nb; | ||||||
| 	cp = xcp; |  | ||||||
| 	memmove(xcp, xcp + nb, xep - xcp + 1);	/* Copies the NUL */ | 	memmove(xcp, xcp + nb, xep - xcp + 1);	/* Copies the NUL */ | ||||||
| 	x_adj_ok = 0;			/* don't redraw */ | 	x_adj_ok = 0;			/* don't redraw */ | ||||||
| 	xlp_valid = false; | 	xlp_valid = false; | ||||||
| @@ -2332,7 +2331,7 @@ x_redraw(int limit) | |||||||
| 		x_displen = xx_cols - 2; | 		x_displen = xx_cols - 2; | ||||||
| 	} | 	} | ||||||
| 	xlp_valid = false; | 	xlp_valid = false; | ||||||
| 	cp = x_lastcp(); | 	x_lastcp(); | ||||||
| 	x_zots(xbp); | 	x_zots(xbp); | ||||||
| 	if (xbp != xbuf || xep > xlp) | 	if (xbp != xbuf || xep > xlp) | ||||||
| 		limit = xx_cols; | 		limit = xx_cols; | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #include "sh.h" | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.70 2008/09/30 19:36:16 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.71 2008/10/13 23:06:02 tg Exp $"); | ||||||
|  |  | ||||||
| /*- | /*- | ||||||
|  * MirOS: This is the default mapping type, and need not be specified. |  * MirOS: This is the default mapping type, and need not be specified. | ||||||
| @@ -283,7 +283,7 @@ hist_execute(char *cmd) | |||||||
| 		histsave(&hist_source->line, p, true, true); | 		histsave(&hist_source->line, p, true, true); | ||||||
|  |  | ||||||
| 		shellf("%s\n", p); /* POSIX doesn't say this is done... */ | 		shellf("%s\n", p); /* POSIX doesn't say this is done... */ | ||||||
| 		if ((p = q)) /* restore \n (trailing \n not restored) */ | 		if (q)		/* restore \n (trailing \n not restored) */ | ||||||
| 			q[-1] = '\n'; | 			q[-1] = '\n'; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								jobs.c
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								jobs.c
									
									
									
									
									
								
							| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #include "sh.h" | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.36 2008/05/17 19:03:25 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.37 2008/10/13 23:06:03 tg Exp $"); | ||||||
|  |  | ||||||
| /* Order important! */ | /* Order important! */ | ||||||
| #define PRUNNING	0 | #define PRUNNING	0 | ||||||
| @@ -319,7 +319,8 @@ exchild(struct op *t, int flags, /* used if XPCLOSE or XCCLOSE */ int close_fd) | |||||||
| 			    "exchild: XPIPEI and no last_job - pid %d", | 			    "exchild: XPIPEI and no last_job - pid %d", | ||||||
| 			    (int)procpid); | 			    (int)procpid); | ||||||
| 		j = last_job; | 		j = last_job; | ||||||
| 		last_proc->next = p; | 		if (last_proc) | ||||||
|  | 			last_proc->next = p; | ||||||
| 		last_proc = p; | 		last_proc = p; | ||||||
| 	} else { | 	} else { | ||||||
| 		j = new_job(); /* fills in j->job */ | 		j = new_job(); /* fills in j->job */ | ||||||
| @@ -402,18 +403,16 @@ exchild(struct op *t, int flags, /* used if XPCLOSE or XCCLOSE */ int close_fd) | |||||||
| 				    SS_RESTORE_DFL|SS_FORCE); | 				    SS_RESTORE_DFL|SS_FORCE); | ||||||
| 		} | 		} | ||||||
| 		if (Flag(FBGNICE) && (flags & XBGND)) | 		if (Flag(FBGNICE) && (flags & XBGND)) | ||||||
| 			i = nice(4); | 			(void)nice(4); | ||||||
| 		if ((flags & XBGND) && !Flag(FMONITOR)) { | 		if ((flags & XBGND) && !Flag(FMONITOR)) { | ||||||
| 			setsig(&sigtraps[SIGINT], SIG_IGN, | 			setsig(&sigtraps[SIGINT], SIG_IGN, | ||||||
| 			    SS_RESTORE_IGN|SS_FORCE); | 			    SS_RESTORE_IGN|SS_FORCE); | ||||||
| 			setsig(&sigtraps[SIGQUIT], SIG_IGN, | 			setsig(&sigtraps[SIGQUIT], SIG_IGN, | ||||||
| 			    SS_RESTORE_IGN|SS_FORCE); | 			    SS_RESTORE_IGN|SS_FORCE); | ||||||
| 			if (!(flags & (XPIPEI | XCOPROC))) { | 			if ((!(flags & (XPIPEI | XCOPROC))) && | ||||||
| 				int fd = open("/dev/null", 0); | 			    ((i = open("/dev/null", 0)) > 0)) { | ||||||
| 				if (fd != 0) { | 				(void)ksh_dup2(i, 0, true); | ||||||
| 					(void) ksh_dup2(fd, 0, true); | 				close(i); | ||||||
| 					close(fd); |  | ||||||
| 				} |  | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		remove_job(j, "child");	/* in case of $(jobs) command */ | 		remove_job(j, "child");	/* in case of $(jobs) command */ | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								misc.c
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								misc.c
									
									
									
									
									
								
							| @@ -6,7 +6,7 @@ | |||||||
| #include <grp.h> | #include <grp.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.85 2008/07/18 11:33:12 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.86 2008/10/13 23:06:03 tg Exp $"); | ||||||
|  |  | ||||||
| #undef USE_CHVT | #undef USE_CHVT | ||||||
| #if defined(TIOCSCTTY) && !defined(MKSH_SMALL) | #if defined(TIOCSCTTY) && !defined(MKSH_SMALL) | ||||||
| @@ -773,11 +773,11 @@ pat_scan(const unsigned char *p, const unsigned char *pe, int match_sep) | |||||||
| 			continue; | 			continue; | ||||||
| 		if ((*++p == /*(*/ ')' && nest-- == 0) || | 		if ((*++p == /*(*/ ')' && nest-- == 0) || | ||||||
| 		    (*p == '|' && match_sep && nest == 0)) | 		    (*p == '|' && match_sep && nest == 0)) | ||||||
| 			return ++p; | 			return (p + 1); | ||||||
| 		if ((*p & 0x80) && vstrchr("*+?@! ", *p & 0x7f)) | 		if ((*p & 0x80) && vstrchr("*+?@! ", *p & 0x7f)) | ||||||
| 			nest++; | 			nest++; | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	return (NULL); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| @@ -1137,7 +1137,7 @@ make_path(const char *cwd, const char *file, | |||||||
| 			for (pend = plist; *pend && *pend != ':'; pend++) | 			for (pend = plist; *pend && *pend != ':'; pend++) | ||||||
| 				; | 				; | ||||||
| 			plen = pend - plist; | 			plen = pend - plist; | ||||||
| 			*cdpathp = *pend ? ++pend : NULL; | 			*cdpathp = *pend ? pend + 1 : NULL; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if ((use_cdpath == 0 || !plen || plist[0] != '/') && | 		if ((use_cdpath == 0 || !plen || plist[0] != '/') && | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								sh.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								sh.h
									
									
									
									
									
								
							| @@ -100,9 +100,9 @@ | |||||||
| #define __SCCSID(x)	__IDSTRING(sccsid,x) | #define __SCCSID(x)	__IDSTRING(sccsid,x) | ||||||
|  |  | ||||||
| #ifdef EXTERN | #ifdef EXTERN | ||||||
| __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.239 2008/10/10 21:30:42 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.240 2008/10/13 23:06:03 tg Exp $"); | ||||||
| #endif | #endif | ||||||
| #define MKSH_VERSION "R35 2008/10/10" | #define MKSH_VERSION "R35 2008/10/13" | ||||||
|  |  | ||||||
| #ifndef MKSH_INCLUDES_ONLY | #ifndef MKSH_INCLUDES_ONLY | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								tree.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								tree.c
									
									
									
									
									
								
							| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #include "sh.h" | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.19 2008/09/14 20:29:13 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.20 2008/10/13 23:06:04 tg Exp $"); | ||||||
|  |  | ||||||
| #define INDENT	4 | #define INDENT	4 | ||||||
|  |  | ||||||
| @@ -262,7 +262,7 @@ tputS(char *wp, struct shf *shf) | |||||||
| 	 *	COMSUB [(`] ...\0	(handle $ ` \ and maybe " in `...` case) | 	 *	COMSUB [(`] ...\0	(handle $ ` \ and maybe " in `...` case) | ||||||
| 	 */ | 	 */ | ||||||
| 	while (1) | 	while (1) | ||||||
| 		switch ((c = *wp++)) { | 		switch (*wp++) { | ||||||
| 		case EOS: | 		case EOS: | ||||||
| 			return; | 			return; | ||||||
| 		case ADELIM: | 		case ADELIM: | ||||||
| @@ -541,7 +541,7 @@ wdstrip(const char *wp, bool keepq, bool make_magic) | |||||||
| 	 *	x${foo:-'hi'} -> x${foo:-hi} unless keepq | 	 *	x${foo:-'hi'} -> x${foo:-hi} unless keepq | ||||||
| 	 */ | 	 */ | ||||||
| 	while (1) | 	while (1) | ||||||
| 		switch ((c = *wp++)) { | 		switch (*wp++) { | ||||||
| 		case EOS: | 		case EOS: | ||||||
| 			return shf_sclose(&shf); /* null terminates */ | 			return shf_sclose(&shf); /* null terminates */ | ||||||
| 		case ADELIM: | 		case ADELIM: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user