oksh-noxz

[fork] Portable OpenBSD ksh, based on the Public Domain Korn Shell (pdksh).
git clone https://noxz.tech/git/oksh-noxz.git
oksh-noxz

commit: afb27d68247aecdf992fec87598bce9d81aaeaf1
parent: 7b72283629c5fd00a8f348f76827c01ac17ec570
author: case <casey.d.mattingly@wellsfargo.com>
date:   Wed, 10 May 2017 00:18:05 -0400
cleanup errors for clang.
Memacs.c16++++++++--------
Mexec.c2+-
Mexpr.c2+-
Mjobs.c2+-
Mlex.c9++++-----
Mmain.c2+-
Mmisc.c16++++++++--------
Mportable/darwin/darwin.h3+++
Mportable/linux/linux.h2++
Mvar.c4++--
10 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/emacs.c b/emacs.c
@@ -863,7 +863,7 @@ kb_find_hist_func(char c)
 	line[0] = c;
 	line[1] = '\0';
 	TAILQ_FOREACH(k, &kblist, entry)
-		if (!strcmp(k->seq, line))
+		if (!strcmp((const char *)k->seq, line))
 			return (k->ftab->xf_func);
 
 	return (x_insert);
@@ -1344,7 +1344,7 @@ kb_add_string(void *func, void *args, char *str)
 	k->ftab = xf;
 	k->args = args ? strdup(args) : NULL;
 
-	strlcpy(k->seq, str, count + 1);
+	strlcpy((char *)k->seq, str, count + 1);
 
 	TAILQ_INSERT_TAIL(&kblist, k, entry);
 
@@ -1377,9 +1377,9 @@ kb_print(struct kb_entry *k)
 {
 	if (!(k->ftab->xf_flags & XF_NOBIND))
 		shprintf("%s = %s\n",
-		    kb_decode(k->seq), k->ftab->xf_name);
+		  kb_decode((const char *)k->seq), k->ftab->xf_name);
 	else if (k->args) {
-		shprintf("%s = ", kb_decode(k->seq));
+	     shprintf("%s = ", kb_decode((const char *)k->seq));
 		shprintf("'%s'\n", kb_decode(k->args));
 	}
 }
@@ -1421,7 +1421,7 @@ x_bind(const char *a1, const char *a2,
 	if (a2 == NULL) {
 		/* print binding */
 		TAILQ_FOREACH(k, &kblist, entry)
-			if (!strcmp(k->seq, in)) {
+			if (!strcmp((const char *)k->seq, in)) {
 				kb_print(k);
 				return (0);
 			}
@@ -1432,7 +1432,7 @@ x_bind(const char *a1, const char *a2,
 	if (strlen(a2) == 0) {
 		/* clear binding */
 		TAILQ_FOREACH_SAFE(k, &kblist, entry, kb)
-			if (!strcmp(k->seq, in)) {
+			if (!strcmp((const char *)k->seq, in)) {
 				kb_del(k);
 				break;
 			}
@@ -1443,7 +1443,7 @@ x_bind(const char *a1, const char *a2,
 	if (macro) {
 		/* delete old mapping */
 		TAILQ_FOREACH_SAFE(k, &kblist, entry, kb)
-			if (!strcmp(k->seq, in)) {
+			if (!strcmp((const char *)k->seq, in)) {
 				kb_del(k);
 				break;
 			}
@@ -1458,7 +1458,7 @@ x_bind(const char *a1, const char *a2,
 		if (!strcmp(x_ftab[i].xf_name, a2)) {
 			/* delete old mapping */
 			TAILQ_FOREACH_SAFE(k, &kblist, entry, kb)
-				if (!strcmp(k->seq, in)) {
+				if (!strcmp((const char *)k->seq, in)) {
 					kb_del(k);
 					break;
 				}
diff --git a/exec.c b/exec.c
@@ -107,7 +107,7 @@ execute(struct op *volatile t,
 				 */
 				if (tp && tp->type == CSHELL &&
 				    (tp->flag & SPEC_BI))
-					errorf(null);
+					errorf("%s", null);
 				/* Deal with FERREXIT, quitenv(), etc. */
 				goto Break;
 			}
diff --git a/expr.c b/expr.c
@@ -187,7 +187,7 @@ v_evaluate(struct tbl *vp, const char *expr, volatile int error_ok,
 		if (i == LAEXPR) {
 			if (error_ok == KSH_RETURN_ERROR)
 				return 0;
-			errorf(null);
+			errorf("%s", null);
 		}
 		unwind(i);
 		/* NOTREACHED */
diff --git a/jobs.c b/jobs.c
@@ -741,7 +741,7 @@ j_resume(const char *cp, int bg)
 		}
 		shprintf("%s%s", p->command, p->next ? "| " : null);
 	}
-	shprintf(newline);
+	shprintf("%s", newline);
 	shf_flush(shl_stdout);
 	if (running)
 		j->state = PRUNNING;
diff --git a/lex.c b/lex.c
@@ -3,11 +3,10 @@
 /*
  * lexical analysis and source input
  */
-
-#include "sh.h"
-#include <libgen.h>
 #include <ctype.h>
-
+#include <libgen.h>
+#include <time.h>
+#include "sh.h"
 
 /* Structure to keep track of the lexing state and the various pieces of info
  * needed for each particular state.
@@ -909,7 +908,7 @@ yyerror(const char *fmt, ...)
 	va_start(va, fmt);
 	shf_vfprintf(shl_out, fmt, va);
 	va_end(va);
-	errorf(null);
+	errorf("%s", null);
 }
 
 /*
diff --git a/main.c b/main.c
@@ -519,7 +519,7 @@ shell(Source *volatile s, volatile int toplevel)
 		case LSHELL:
 			if (interactive) {
 				if (i == LINTR)
-					shellf(newline);
+					shellf("%s", newline);
 				/* Reset any eof that was read as part of a
 				 * multiline command.
 				 */
diff --git a/misc.c b/misc.c
@@ -240,7 +240,7 @@ printoptions(int verbose)
 		for (i = 0; i < NELEM(options); i++)
 			if (Flag(i) && options[i].name)
 				shprintf(" -o %s", options[i].name);
-		shprintf(newline);
+		shprintf("%s", newline);
 	}
 }
 
@@ -715,7 +715,7 @@ posix_cclass(const unsigned char *pattern, int test, const unsigned char **ep)
 	size_t len;
 	int rval = 0;
 
-	if ((colon = strchr(pattern, ':')) == NULL || colon[1] != MAGIC) {
+	if ((colon = ((const unsigned char *)strchr((const char *)pattern, ':'))) == NULL || colon[1] != MAGIC) {
 		*ep = pattern - 2;
 		return -1;
 	}
@@ -723,7 +723,7 @@ posix_cclass(const unsigned char *pattern, int test, const unsigned char **ep)
 	len = (size_t)(colon - pattern);
 
 	for (cc = cclasses; cc->name != NULL; cc++) {
-		if (!strncmp(pattern, cc->name, len) && cc->name[len] == '\0') {
+		if (!strncmp((const char *)pattern, cc->name, len) && cc->name[len] == '\0') {
 			if (cc->isctype(test))
 				rval = 1;
 			break;
@@ -748,8 +748,8 @@ cclass(const unsigned char *p, int sub)
 		if ((p[0] == MAGIC && p[1] == '[' && p[2] == ':') ||
 		    (p[0] == '[' && p[1] == ':')) {
 			do {
-				const char *pp = p + (*p == MAGIC) + 2;
-				rv = posix_cclass(pp, sub, &p);
+				const char *pp = (const char *)p + (*p == MAGIC) + 2;
+				rv = posix_cclass((const unsigned char *)pp, sub, &p);
 				switch (rv) {
 				case 1:
 					found = 1;
@@ -906,7 +906,7 @@ ksh_getopt(char **argv, Getopt *go, const char *options)
 			    (go->flags & GF_NONAME) ? "" : argv[0],
 			    (go->flags & GF_NONAME) ? "" : ": ", c);
 			if (go->flags & GF_ERROR)
-				bi_errorf(null);
+				bi_errorf("%s", null);
 		}
 		return '?';
 	}
@@ -932,7 +932,7 @@ ksh_getopt(char **argv, Getopt *go, const char *options)
 			    (go->flags & GF_NONAME) ? "" : argv[0],
 			    (go->flags & GF_NONAME) ? "" : ": ", c);
 			if (go->flags & GF_ERROR)
-				bi_errorf(null);
+				bi_errorf("%s", null);
 			return '?';
 		}
 		go->p = 0;
@@ -984,7 +984,7 @@ print_value_quoted(const char *s)
 	}
 	for (p = s; *p; p++) {
 		if (*p == '\'') {
-			shprintf("'\\'" + 1 - inquote);
+			shprintf("%s", "'\\'" + 1 - inquote);
 			inquote = 0;
 		} else {
 			if (!inquote) {
diff --git a/portable/darwin/darwin.h b/portable/darwin/darwin.h
@@ -12,3 +12,6 @@
 /* Not really sure on these two, but it seems to work ok. */
 #define setresgid(x, y, z)	setgid(x); setegid(y); setgid(z)
 #define setresuid(x, y, z)	setuid(x); seteuid(y); setuid(z)
+
+long long strtonum(const char *numstr, long long minval, long long maxval,
+		   const char **errstrp);
diff --git a/portable/linux/linux.h b/portable/linux/linux.h
@@ -18,3 +18,5 @@ mode_t	getmode(const void *, mode_t);
 void   *setmode(const char *);
 size_t	strlcat(char *, const char *, size_t);
 size_t	strlcpy(char *, const char *, size_t);
+long long strtonum(const char *numstr, long long minval, long long maxval,
+		   const char **errstrp);
diff --git a/var.c b/var.c
@@ -357,7 +357,7 @@ setstr(struct tbl *vq, const char *s, int error_ok)
 	if ((vq->flag & RDONLY) && !no_ro_check) {
 		warningf(true, "%s: is read only", vq->name);
 		if (!error_ok)
-			errorf(null);
+			errorf("%s", null);
 		return 0;
 	}
 	if (!(vq->flag&INTEGER)) { /* string dest */
@@ -711,7 +711,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
 			}
 		}
 		if (!ok)
-		    errorf(null);
+		    errorf("%s", null);
 	}
 
 	if (val != NULL) {