zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: minor coverity issues with sizeof parameters
@ 2014-11-28 19:01 Oliver Kiddle
  0 siblings, 0 replies; only message in thread
From: Oliver Kiddle @ 2014-11-28 19:01 UTC (permalink / raw)
  To: Zsh workers

Coverity complains in a few cases where we do something like:
  char **arr = malloc(x * sizeof(char **));
It should really be sizeof(char *). It doesn't really matter because a
char * is the same size as a char ** on any existing system I've ever
encountered. This patch fixes them.

If anyone is interested in helping to go through the coverity results,
sign up at scan.coverity.com, search for the zsh project and request
access.

Oliver

diff --git a/Src/Builtins/sched.c b/Src/Builtins/sched.c
index c1cc983..bcf7661 100644
--- a/Src/Builtins/sched.c
+++ b/Src/Builtins/sched.c
@@ -346,7 +346,7 @@ schedgetfn(UNUSED(Param pm))
     for (i = 0, sch = schedcmds; sch; sch = sch->next, i++)
 	;
 
-    aptr = ret = zhalloc(sizeof(char **) * (i+1));
+    aptr = ret = zhalloc(sizeof(char *) * (i+1));
     for (sch = schedcmds; sch; sch = sch->next, aptr++) {
 	char tbuf[40], *flagstr;
 	time_t t;
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 2e1a527..c129940 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -2059,8 +2059,8 @@ complistmatches(UNUSED(Hookdef dummy), Chdata dat)
 
 	i = zterm_columns * listdat.nlines;
 	free(mtab);
-	mtab = (Cmatch **) zalloc(i * sizeof(Cmatch **));
-	memset(mtab, 0, i * sizeof(Cmatch **));
+	mtab = (Cmatch **) zalloc(i * sizeof(Cmatch *));
+	memset(mtab, 0, i * sizeof(Cmatch *));
 	free(mgtab);
 	mgtab = (Cmgroup *) zalloc(i * sizeof(Cmgroup));
 #ifdef DEBUG
diff --git a/Src/exec.c b/Src/exec.c
index 02a8fe3..79fffa0 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2291,13 +2291,13 @@ addvars(Estate state, Wordcode pc, int addflags)
 	    continue;
 	}
 	if (vl) {
-	    ptr = arr = (char **) zalloc(sizeof(char **) *
+	    ptr = arr = (char **) zalloc(sizeof(char *) *
 					 (countlinknodes(vl) + 1));
 
 	    while (nonempty(vl))
 		*ptr++ = ztrdup((char *) ugetnode(vl));
 	} else
-	    ptr = arr = (char **) zalloc(sizeof(char **));
+	    ptr = arr = (char **) zalloc(sizeof(char *));
 
 	*ptr = NULL;
 	if (xtr) {
diff --git a/Src/sort.c b/Src/sort.c
index 3d00bb5..92ee1c0 100644
--- a/Src/sort.c
+++ b/Src/sort.c
@@ -368,7 +368,7 @@ strmetasort(char **array, int sortwhat, int *unmetalenp)
     sortdir = (sortwhat & SORTIT_BACKWARDS) ? -1 : 1;
     sortnumeric = (sortwhat & SORTIT_NUMERICALLY) ? 1 : 0;
 
-    qsort(sortptrarr, nsort, sizeof(SortElt *), eltpcmp);
+    qsort(sortptrarr, nsort, sizeof(SortElt), eltpcmp);
 
     sortnumeric = oldsortnumeric;
     sortdir = oldsortdir;
diff --git a/Src/utils.c b/Src/utils.c
index c6e7aed..34fc91a 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -693,12 +693,12 @@ slashsplit(char *s)
     int t0;
 
     if (!*s)
-	return (char **) zshcalloc(sizeof(char **));
+	return (char **) zshcalloc(sizeof(char *));
 
     for (t = s, t0 = 0; *t; t++)
 	if (*t == '/')
 	    t0++;
-    q = r = (char **) zalloc(sizeof(char **) * (t0 + 2));
+    q = r = (char **) zalloc(sizeof(char *) * (t0 + 2));
 
     while ((t = strchr(s, '/'))) {
 	*q++ = ztrduppfx(s, t - s);
@@ -2953,7 +2953,7 @@ colonsplit(char *s, int uniq)
     for (t = s, ct = 0; *t; t++) /* count number of colons */
 	if (*t == ':')
 	    ct++;
-    ptr = ret = (char **) zalloc(sizeof(char **) * (ct + 2));
+    ptr = ret = (char **) zalloc(sizeof(char *) * (ct + 2));
 
     t = s;
     do {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-28 19:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-28 19:01 PATCH: minor coverity issues with sizeof parameters Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).