(very few) fixes and a couple of workarounds for Coverity
This commit is contained in:
		
							
								
								
									
										9
									
								
								edit.c
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								edit.c
									
									
									
									
									
								
							| @@ -28,7 +28,7 @@ | |||||||
|  |  | ||||||
| #ifndef MKSH_NO_CMDLINE_EDITING | #ifndef MKSH_NO_CMDLINE_EDITING | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.320 2017/04/12 15:54:47 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.321 2017/04/12 16:46:20 tg Exp $"); | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * in later versions we might use libtermcap for this, but since external |  * in later versions we might use libtermcap for this, but since external | ||||||
| @@ -1786,12 +1786,11 @@ x_newline(int c MKSH_A_UNUSED) | |||||||
| static int | static int | ||||||
| x_end_of_text(int c MKSH_A_UNUSED) | x_end_of_text(int c MKSH_A_UNUSED) | ||||||
| { | { | ||||||
| 	unsigned char tmp; | 	unsigned char tmp[1], *cp = tmp; | ||||||
| 	char *cp = (void *)&tmp; |  | ||||||
|  |  | ||||||
| 	tmp = isedchar(edchars.eof) ? (unsigned char)edchars.eof : | 	*tmp = isedchar(edchars.eof) ? (unsigned char)edchars.eof : | ||||||
| 	    (unsigned char)CTRL('D'); | 	    (unsigned char)CTRL('D'); | ||||||
| 	x_zotc3(&cp); | 	x_zotc3((char **)&cp); | ||||||
| 	x_putc('\r'); | 	x_putc('\r'); | ||||||
| 	x_putc('\n'); | 	x_putc('\n'); | ||||||
| 	x_flush(); | 	x_flush(); | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								exec.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								exec.c
									
									
									
									
									
								
							| @@ -23,7 +23,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #include "sh.h" | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.195 2017/04/08 01:07:15 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.196 2017/04/12 16:46:21 tg Exp $"); | ||||||
|  |  | ||||||
| #ifndef MKSH_DEFAULT_EXECSHELL | #ifndef MKSH_DEFAULT_EXECSHELL | ||||||
| #define MKSH_DEFAULT_EXECSHELL	MKSH_UNIXROOT "/bin/sh" | #define MKSH_DEFAULT_EXECSHELL	MKSH_UNIXROOT "/bin/sh" | ||||||
| @@ -376,9 +376,8 @@ execute(struct op * volatile t, | |||||||
| 		if (t->right == NULL) | 		if (t->right == NULL) | ||||||
| 			/* should be error */ | 			/* should be error */ | ||||||
| 			break; | 			break; | ||||||
| 		rv = execute(t->left, XERROK, NULL) == 0 ? | 		rv = execute(execute(t->left, XERROK, NULL) == 0 ? | ||||||
| 		    execute(t->right->left, flags & XERROK, xerrok) : | 		    t->right->left : t->right->right, flags & XERROK, xerrok); | ||||||
| 		    execute(t->right->right, flags & XERROK, xerrok); |  | ||||||
| 		break; | 		break; | ||||||
|  |  | ||||||
| 	case TCASE: | 	case TCASE: | ||||||
| @@ -1507,7 +1506,10 @@ iosetup(struct ioword *iop, struct tbl *tp) | |||||||
| 		if (u == -1) { | 		if (u == -1) { | ||||||
| 			u = errno; | 			u = errno; | ||||||
| 			warningf(true, Tf_cant_ss_s, | 			warningf(true, Tf_cant_ss_s, | ||||||
|  | #if 0 | ||||||
|  | 			    /* can't happen */ | ||||||
| 			    iotype == IODUP ? "dup" : | 			    iotype == IODUP ? "dup" : | ||||||
|  | #endif | ||||||
| 			    (iotype == IOREAD || iotype == IOHERE) ? | 			    (iotype == IOREAD || iotype == IOHERE) ? | ||||||
| 			    Topen : Tcreate, cp, cstrerror(u)); | 			    Topen : Tcreate, cp, cstrerror(u)); | ||||||
| 		} | 		} | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								misc.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								misc.c
									
									
									
									
									
								
							| @@ -30,7 +30,7 @@ | |||||||
| #include <grp.h> | #include <grp.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.254 2017/04/02 13:08:06 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.255 2017/04/12 16:46:22 tg Exp $"); | ||||||
|  |  | ||||||
| #define KSH_CHVT_FLAG | #define KSH_CHVT_FLAG | ||||||
| #ifdef MKSH_SMALL | #ifdef MKSH_SMALL | ||||||
| @@ -501,7 +501,7 @@ parse_args(const char **argv, | |||||||
| 	if (arrayset) { | 	if (arrayset) { | ||||||
| 		const char *ccp = NULL; | 		const char *ccp = NULL; | ||||||
|  |  | ||||||
| 		if (*array) | 		if (array && *array) | ||||||
| 			ccp = skip_varname(array, false); | 			ccp = skip_varname(array, false); | ||||||
| 		if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) { | 		if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) { | ||||||
| 			bi_errorf(Tf_sD_s, array, Tnot_ident); | 			bi_errorf(Tf_sD_s, array, Tnot_ident); | ||||||
|   | |||||||
							
								
								
									
										33
									
								
								shf.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								shf.c
									
									
									
									
									
								
							| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| /*- | /*- | ||||||
|  * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, |  * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, | ||||||
|  *		 2012, 2013, 2015, 2016 |  *		 2012, 2013, 2015, 2016, 2017 | ||||||
|  *	mirabilos <m@mirbsd.org> |  *	mirabilos <m@mirbsd.org> | ||||||
|  * |  * | ||||||
|  * Provided that these terms and disclaimer and all copyright notices |  * Provided that these terms and disclaimer and all copyright notices | ||||||
| @@ -25,7 +25,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #include "sh.h" | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/shf.c,v 1.77 2017/04/02 15:00:45 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/shf.c,v 1.78 2017/04/12 16:46:22 tg Exp $"); | ||||||
|  |  | ||||||
| /* flags to shf_emptybuf() */ | /* flags to shf_emptybuf() */ | ||||||
| #define EB_READSW	0x01	/* about to switch to reading */ | #define EB_READSW	0x01	/* about to switch to reading */ | ||||||
| @@ -289,29 +289,32 @@ shf_sclose(struct shf *shf) | |||||||
| int | int | ||||||
| shf_flush(struct shf *shf) | shf_flush(struct shf *shf) | ||||||
| { | { | ||||||
|  | 	int rv; | ||||||
|  |  | ||||||
| 	if (shf->flags & SHF_STRING) | 	if (shf->flags & SHF_STRING) | ||||||
| 		return ((shf->flags & SHF_WR) ? -1 : 0); | 		rv = (shf->flags & SHF_WR) ? -1 : 0; | ||||||
|  | 	else if (shf->fd < 0) | ||||||
| 	if (shf->fd < 0) |  | ||||||
| 		internal_errorf(Tf_sD_s, "shf_flush", "no fd"); | 		internal_errorf(Tf_sD_s, "shf_flush", "no fd"); | ||||||
|  | 	else if (shf->flags & SHF_ERROR) { | ||||||
| 	if (shf->flags & SHF_ERROR) { |  | ||||||
| 		errno = shf->errnosv; | 		errno = shf->errnosv; | ||||||
| 		return (-1); | 		rv = -1; | ||||||
| 	} | 	} else if (shf->flags & SHF_READING) { | ||||||
|  | 		rv = 0; | ||||||
| 	if (shf->flags & SHF_READING) { |  | ||||||
| 		shf->flags &= ~(SHF_EOF | SHF_READING); | 		shf->flags &= ~(SHF_EOF | SHF_READING); | ||||||
| 		if (shf->rnleft > 0) { | 		if (shf->rnleft > 0) { | ||||||
| 			lseek(shf->fd, (off_t)-shf->rnleft, SEEK_CUR); | 			if (lseek(shf->fd, (off_t)-shf->rnleft, | ||||||
|  | 			    SEEK_CUR) == -1) { | ||||||
|  | 				shf->flags |= SHF_ERROR; | ||||||
|  | 				shf->errnosv = errno; | ||||||
|  | 				rv = -1; | ||||||
|  | 			} | ||||||
| 			shf->rnleft = 0; | 			shf->rnleft = 0; | ||||||
| 			shf->rp = shf->buf; | 			shf->rp = shf->buf; | ||||||
| 		} | 		} | ||||||
| 		return (0); |  | ||||||
| 	} else if (shf->flags & SHF_WRITING) | 	} else if (shf->flags & SHF_WRITING) | ||||||
| 		return (shf_emptybuf(shf, 0)); | 		rv = shf_emptybuf(shf, 0); | ||||||
|  |  | ||||||
| 	return (0); | 	return (rv); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								tree.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tree.c
									
									
									
									
									
								
							| @@ -23,7 +23,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #include "sh.h" | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.88 2017/04/11 12:34:04 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.89 2017/04/12 16:46:23 tg Exp $"); | ||||||
|  |  | ||||||
| #define INDENT	8 | #define INDENT	8 | ||||||
|  |  | ||||||
| @@ -58,7 +58,7 @@ ptree(struct op *t, int indent, struct shf *shf) | |||||||
| 	case TCOM: | 	case TCOM: | ||||||
| 		prevent_semicolon = false; | 		prevent_semicolon = false; | ||||||
| 		/* special-case 'var=<<EOF' (cf. exec.c:execute) */ | 		/* special-case 'var=<<EOF' (cf. exec.c:execute) */ | ||||||
| 		if ( | 		if (t->args && | ||||||
| 		    /* we have zero arguments, i.e. no program to run */ | 		    /* we have zero arguments, i.e. no program to run */ | ||||||
| 		    t->args[0] == NULL && | 		    t->args[0] == NULL && | ||||||
| 		    /* we have exactly one variable assignment */ | 		    /* we have exactly one variable assignment */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user