summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2020-04-11 12:41:09 +0300
committerToomas Soome <tsoome@me.com>2020-06-19 23:20:07 +0300
commitc686756220120076a07be0dcce54be698101a3d1 (patch)
tree7e2105ba6bd28f6cc2367b8617c7c5e8d1801047
parentd865fc92e4b640c73c2957a20b3d82622c741be5 (diff)
downloadillumos-joyent-c686756220120076a07be0dcce54be698101a3d1.tar.gz
12541 sgs: smatch and NULL pointer errors
Reviewed by: Yuri Pankov <ypankov@tintri.com> Reviewed by: Gary Mills <gary_mills@fastmail.fm> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/cmd/sgs/error/common/errorinput.c30
-rw-r--r--usr/src/cmd/sgs/error/common/errorsubr.c25
-rw-r--r--usr/src/cmd/sgs/error/common/errortouch.c58
-rw-r--r--usr/src/cmd/sgs/rtld/common/a.out.c4
-rw-r--r--usr/src/cmd/sgs/rtld/common/cache_a.out.c79
5 files changed, 98 insertions, 98 deletions
diff --git a/usr/src/cmd/sgs/error/common/errorinput.c b/usr/src/cmd/sgs/error/common/errorinput.c
index eae36879aa..1f02ab6923 100644
--- a/usr/src/cmd/sgs/error/common/errorinput.c
+++ b/usr/src/cmd/sgs/error/common/errorinput.c
@@ -25,8 +25,6 @@
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <stdio.h>
#include <ctype.h>
#include <string.h>
@@ -129,7 +127,7 @@ erroradd(int errorlength, char **errorv, Errorclass errorclass,
#ifdef FULLDEBUG
if (errorclass != C_TRUE)
printf("The 2nd word, \"%s\" is not a number.\n",
- errorv[1]);
+ errorv[1]);
#endif
}
if (errorlength > 0) {
@@ -143,10 +141,10 @@ erroradd(int errorlength, char **errorv, Errorclass errorclass,
newerror->error_s_class = errorsubclass;
switch (newerror->error_e_class = discardit(newerror)) {
case C_SYNC: nsyncerrors++; break;
- case C_DISCARD: ndiscard++; break;
+ case C_DISCARD: ndiscard++; break;
case C_NULLED: nnulled++; break;
case C_NONSPEC: nnonspec++; break;
- case C_THISFILE: nthisfile++; break;
+ case C_THISFILE: nthisfile++; break;
case C_TRUE: ntrue++; break;
case C_UNKNOWN: nunknown++; break;
case C_IGNORE: nignore++; break;
@@ -315,7 +313,7 @@ Errorclass
lint0(void)
{
char **nwordv;
- char *line, *file;
+ char *line, *file;
/*
* Attempt a match for the new lint style normal compiler
* error messages, of the form
@@ -453,8 +451,8 @@ f77(void)
return (C_UNKNOWN);
if ((lastchar(wordv[6]) == ':') &&
((wordvcmp(wordv+1, 3, F77_fatal) == 0) ||
- (wordvcmp(wordv+1, 3, F77_error) == 0) ||
- (wordvcmp(wordv+1, 3, F77_warning) == 0))) {
+ (wordvcmp(wordv+1, 3, F77_error) == 0) ||
+ (wordvcmp(wordv+1, 3, F77_warning) == 0))) {
language = INF77;
nwordv = wordvsplice(2, wordc, wordv+1);
nwordv[0] = wordv[6];
@@ -564,10 +562,10 @@ mod2(void)
*/
if (((strcmp(wordv[1], "!!!") == 0) || /* early version */
(strcmp(wordv[1], "File") == 0)) && /* later version */
- (lastchar(wordv[2]) == ',') && /* file name */
- (strcmp(wordv[3], "line") == 0) &&
- (isdigit(firstchar(wordv[4]))) && /* line number */
- (lastchar(wordv[4]) == ':')) { /* line number */
+ (lastchar(wordv[2]) == ',') && /* file name */
+ (strcmp(wordv[3], "line") == 0) &&
+ (isdigit(firstchar(wordv[4]))) && /* line number */
+ (lastchar(wordv[4]) == ':')) { /* line number */
clob_last(wordv[2], '\0'); /* drop last , on file name */
clob_last(wordv[4], '\0'); /* drop last : on line number */
wordv[3] = wordv[2]; /* file name on top of "line" */
@@ -596,10 +594,10 @@ sunf77(void)
(strcmp(wordv[2], "line") == 0) &&
(isdigit(firstchar(wordv[3]))) &&
(lastchar(wordv[3]) == ':') &&
- ((strcmp(wordv[4], "Error:") == 0) ||
- (strcmp(wordv[4], "Warning:") == 0) ||
- ((strcmp(wordv[4], "ANSI") == 0) &&
- (strcmp(wordv[5], "extension:") == 0)))) {
+ ((strcmp(wordv[4], "Error:") == 0) ||
+ (strcmp(wordv[4], "Warning:") == 0) ||
+ ((strcmp(wordv[4], "ANSI") == 0) &&
+ (strcmp(wordv[5], "extension:") == 0)))) {
clob_last(wordv[1], '\0'); /* drop last , */
clob_last(wordv[1], '\0'); /* drop last " */
wordv[1]++; /* drop first " */
diff --git a/usr/src/cmd/sgs/error/common/errorsubr.c b/usr/src/cmd/sgs/error/common/errorsubr.c
index e2d0828a4f..17bc104c01 100644
--- a/usr/src/cmd/sgs/error/common/errorsubr.c
+++ b/usr/src/cmd/sgs/error/common/errorsubr.c
@@ -101,10 +101,12 @@ int
position(char *string, char ch)
{
int i;
- if (string)
- for (i = 1; *string; string++, i++) {
- if (*string == ch)
- return (i);
+
+ if (string) {
+ for (i = 1; *string; string++, i++) {
+ if (*string == ch)
+ return (i);
+ }
}
return (-1);
}
@@ -116,13 +118,14 @@ substitute(char *string, char chold, char chnew)
{
char *cp = string;
- if (cp)
- while (*cp) {
- if (*cp == chold) {
- *cp = chnew;
- break;
+ if (cp) {
+ while (*cp) {
+ if (*cp == chold) {
+ *cp = chnew;
+ break;
+ }
+ cp++;
}
- cp++;
}
return (string);
}
@@ -283,7 +286,7 @@ wordvprint(FILE *fyle, int wordc, char *wordv[])
void
wordvbuild(char *string, int *r_wordc, char ***r_wordv)
{
- char *cp;
+ char *cp;
char *saltedbuffer;
char **wordv;
int wordcount;
diff --git a/usr/src/cmd/sgs/error/common/errortouch.c b/usr/src/cmd/sgs/error/common/errortouch.c
index 6773fc0476..fcc3ce9499 100644
--- a/usr/src/cmd/sgs/error/common/errortouch.c
+++ b/usr/src/cmd/sgs/error/common/errortouch.c
@@ -164,14 +164,14 @@ filenames(int nfiles, Eptr **files)
if (nfiles) {
someerrors++;
(void) fprintf(stdout, terse
- ? "%d file%s"
- : "%d file%s contain%s errors",
- nfiles, plural(nfiles), verbform(nfiles));
+ ? "%d file%s"
+ : "%d file%s contain%s errors",
+ nfiles, plural(nfiles), verbform(nfiles));
if (!terse) {
FILEITERATE(fi, 1) {
(void) fprintf(stdout, "%s\"%s\" (%d)",
- sep, (*files[fi])->error_text[0],
- files[fi+1] - files[fi]);
+ sep, (*files[fi])->error_text[0],
+ files[fi+1] - files[fi]);
sep = ", ";
}
}
@@ -201,10 +201,10 @@ nopertain(Eptr **files)
someerrors++;
if (terse) {
(void) fprintf(stdout, "\t%d %s errors NOT PRINTED\n",
- class_count[type], class_table[type]);
+ class_count[type], class_table[type]);
} else {
(void) fprintf(stdout, "\n\t%d %s errors follow\n",
- class_count[type], class_table[type]);
+ class_count[type], class_table[type]);
EITERATE(erpp, files, 0) {
errorp = *erpp;
if (errorp->error_e_class == type) {
@@ -232,9 +232,9 @@ touchfiles(int nfiles, Eptr **files, int *r_edargc, char ***r_edargv)
name = (*files[fi])->error_text[0];
spread = files[fi+1] - files[fi];
(void) fprintf(stdout, terse
- ? "\"%s\" has %d error%s, "
- : "\nFile \"%s\" has %d error%s.\n",
- name, spread, plural(spread));
+ ? "\"%s\" has %d error%s, "
+ : "\nFile \"%s\" has %d error%s.\n",
+ name, spread, plural(spread));
/*
* First, iterate through all error messages in this file
* to see how many of the error messages really will
@@ -336,9 +336,9 @@ settotouch(char *name)
if (query) {
switch (touchstatus = inquire(terse
- ? "Touch? "
- : "Do you want to touch file \"%s\"? ",
- name)) {
+ ? "Touch? "
+ : "Do you want to touch file \"%s\"? ",
+ name)) {
case Q_NO:
case Q_no:
return (dest);
@@ -351,23 +351,23 @@ settotouch(char *name)
case F_NOTREAD:
dest = TOSTDOUT;
(void) fprintf(stdout, terse
- ? "\"%s\" unreadable\n"
- : "File \"%s\" is unreadable\n",
- name);
+ ? "\"%s\" unreadable\n"
+ : "File \"%s\" is unreadable\n",
+ name);
break;
case F_NOTWRITE:
dest = TOSTDOUT;
(void) fprintf(stdout, terse
- ? "\"%s\" unwritable\n"
- : "File \"%s\" is unwritable\n",
- name);
+ ? "\"%s\" unwritable\n"
+ : "File \"%s\" is unwritable\n",
+ name);
break;
case F_NOTEXIST:
dest = TOSTDOUT;
(void) fprintf(stdout,
terse ? "\"%s\" not found\n" :
- "Can't find file \"%s\" to insert error "
- "messages into.\n",
+ "Can't find file \"%s\" to insert error "
+ "messages into.\n",
name);
break;
default:
@@ -389,9 +389,9 @@ diverterrors(char *name, int dest, Eptr **files, int ix,
if ((nerrors != nterrors) && (!previewed)) {
(void) fprintf(stdout, terse
- ? "Uninserted errors\n"
- : ">>Uninserted errors for file \"%s\" follow.\n",
- name);
+ ? "Uninserted errors\n"
+ : ">>Uninserted errors for file \"%s\" follow.\n",
+ name);
}
EITERATE(erpp, files, ix) {
@@ -422,7 +422,7 @@ oktotouch(char *filename)
extern char *suffixlist;
char *src;
char *pat;
- char *osrc;
+ char *osrc;
pat = suffixlist;
if (pat == 0)
@@ -558,8 +558,8 @@ text(Eptr p, boolean use_all)
(void) fputs(lang_table[p->error_language].lang_incomment,
n_touchedfile);
(void) fprintf(n_touchedfile, "%d [%s] ",
- p->error_line,
- lang_table[p->error_language].lang_name);
+ p->error_line,
+ lang_table[p->error_language].lang_name);
wordvprint(n_touchedfile, p->error_lgtext-offset, p->error_text+offset);
(void) fputs(lang_table[p->error_language].lang_outcomment,
n_touchedfile);
@@ -605,8 +605,8 @@ writetouched(int overwrite)
tmpfile = NULL;
if ((localfile = fopen(o_name, "w")) == NULL) {
(void) fprintf(stderr,
- "%s: Can't open file \"%s\" to overwrite.\n",
- processname, o_name);
+ "%s: Can't open file \"%s\" to overwrite.\n",
+ processname, o_name);
botch++;
}
if ((tmpfile = fopen(n_name, "r")) == NULL) {
diff --git a/usr/src/cmd/sgs/rtld/common/a.out.c b/usr/src/cmd/sgs/rtld/common/a.out.c
index 6ea37918ad..693b4f59bc 100644
--- a/usr/src/cmd/sgs/rtld/common/a.out.c
+++ b/usr/src/cmd/sgs/rtld/common/a.out.c
@@ -356,7 +356,7 @@ aout_find_com(struct nlist *sp, const char *name)
(void) strcpy(rs->rtc_sp->n_un.n_name, name);
rs->rtc_sp->n_type = N_COMM;
if ((rs->rtc_sp->n_value =
- (long)calloc(rs->rtc_sp->n_value, 1)) == NULL)
+ (long)calloc(rs->rtc_sp->n_value, 1)) == (long)NULL)
return (NULL);
return (rs->rtc_sp);
}
@@ -419,7 +419,7 @@ aout_findsb(const char *aname, Rt_map *lmp, int flag)
if (*name++ == '\0')
return (sp); /* found */
}
- if (p->next == NULL)
+ if (p->next == 0)
return (NULL); /* not found */
else
continue;
diff --git a/usr/src/cmd/sgs/rtld/common/cache_a.out.c b/usr/src/cmd/sgs/rtld/common/cache_a.out.c
index 0afdcdb5e5..994edaa2fd 100644
--- a/usr/src/cmd/sgs/rtld/common/cache_a.out.c
+++ b/usr/src/cmd/sgs/rtld/common/cache_a.out.c
@@ -38,16 +38,16 @@
#include "_rtld.h"
#include "msg.h"
-static int stol();
-static int rest_ok();
-static int verscmp();
-static void fix_lo();
-static int extract_name();
-static int hash();
+static int stol(char *, char, char **, int *);
+static int rest_ok(char *);
+static int verscmp(const char *, const char *);
+static void fix_lo(struct db *);
+static int extract_name(char **);
+static int hash(char *, int, int);
-static struct link_object *get_lo();
-static struct dbd *new_dbd();
-static struct db *find_so();
+static struct link_object *get_lo(struct db *, char *, int, int, int);
+static struct dbd *new_dbd(struct dbd **, struct db *);
+static struct db *find_so(const char *);
#define SKIP_DOT(str) ((*str == '.') ? ++str : str)
#define EMPTY(str) ((str == NULL) || (*str == '\0'))
@@ -62,9 +62,7 @@ static struct dbd *dbd_head = NULL; /* head of data bases */
* but the highest minor number
*/
char *
-ask_db(dbp, file)
- struct db *dbp;
- const char *file;
+ask_db(struct db *dbp, const char *file)
{
char *libname, *n;
char *mnp;
@@ -82,7 +80,7 @@ ask_db(dbp, file)
if ((libname = malloc(liblen + 1)) == 0)
return (NULL);
(void) strncpy(libname, n, liblen);
- libname[liblen] = NULL;
+ libname[liblen] = '\0';
if (strncmp(MSG_ORIG(MSG_FIL_DOTSODOT), (n + liblen),
MSG_FIL_DOTSODOT_SIZE))
@@ -245,7 +243,7 @@ find_so(const char *ds)
*/
index = hash(cp, cplen, m);
ep = &(dbp->db_hash[index]);
- if (ep->dbe_lop == NULL) {
+ if (ep->dbe_lop == 0) {
ep->dbe_lop = (long)get_lo(dbp, cp,
cplen, m, to_min);
/* LINTED */
@@ -278,7 +276,7 @@ find_so(const char *ds)
dp->d_name);
break;
}
- if (ep->dbe_next == NULL) {
+ if (ep->dbe_next == 0) {
ep->dbe_next = RELPTR(dbp,
calloc(sizeof (struct dbe), 1));
/* LINTED */
@@ -302,14 +300,15 @@ find_so(const char *ds)
/*
* Allocate and fill in the fields for a link_object
+ * Arguments:
+ * struct db *dbp; data base
+ * char *cp; ptr. to X of libX
+ * int cplen; length of X
+ * int m; major version
+ * int n; index to minor version
*/
static struct link_object *
-get_lo(dbp, cp, cplen, m, n)
- struct db *dbp; /* data base */
- char *cp; /* ptr. to X of libX */
- int cplen; /* length of X */
- int m; /* major version */
- int n; /* index to minor version */
+get_lo(struct db *dbp, char *cp, int cplen, int m, int n)
{
struct link_object *lop; /* link_object to be returned */
struct link_object *tlop; /* working copy of the above */
@@ -353,8 +352,7 @@ get_lo(dbp, cp, cplen, m, n)
* length of X
*/
static int
-extract_name(name)
- char **name;
+extract_name(char **name)
{
char *ls; /* string after LIB root */
char *dp; /* string before first delimiter */
@@ -375,8 +373,7 @@ extract_name(name)
* but only one will be chosen.
*/
static void
-fix_lo(dbp)
- struct db *dbp;
+fix_lo(struct db *dbp)
{
int i; /* loop temporary */
int dirlen = strlen(&AP(dbp)[dbp->db_name]);
@@ -408,11 +405,12 @@ fix_lo(dbp)
/*
* Allocate a new dbd, append it after dbdpp and set the dbd_dbp to dbp.
+ * Arguments:
+ * struct dbd **dbdpp; insertion point
+ * struct db *dbp; db associated with this dbd
*/
static struct dbd *
-new_dbd(dbdpp, dbp)
- struct dbd **dbdpp; /* insertion point */
- struct db *dbp; /* db associated with this dbd */
+new_dbd(struct dbd **dbdpp, struct db *dbp)
{
struct dbd *dbdp; /* working dbd ptr. */
@@ -426,12 +424,13 @@ new_dbd(dbdpp, dbp)
/*
* Calculate hash index for link object.
* This is based on X.major from libX.so.major.minor.
+ * Arguments:
+ * char *np; X of libX
+ * int nchrs; no of chrs. to hash on
+ * int m; the major version
*/
static int
-hash(np, nchrs, m)
- char *np; /* X of libX */
- int nchrs; /* no of chrs. to hash on */
- int m; /* the major version */
+hash(char *np, int nchrs, int m)
{
int h; /* for loop counter */
char *cp; /* working (char *) ptr */
@@ -447,8 +446,7 @@ hash(np, nchrs, m)
* Test whether the string is of digit[.digit]* format
*/
static int
-rest_ok(str)
- char *str; /* input string */
+rest_ok(char *str)
{
int dummy; /* integer place holder */
int legal = 1; /* return flag */
@@ -509,14 +507,15 @@ verscmp(const char *c1p, const char *c2p)
* as a decimal digit. It stops interpreting when it reaches a delimiter or
* when character does not represent a digit. In the first case it returns
* success and the latter failure.
+ * Arguments:
+ * char *cp; ptr to input string
+ * char delimit; delimiter
+ * char **ptr; left pointing to next del. or
+ * illegal character
+ * int *i; digit that the string represents
*/
static int
-stol(cp, delimit, ptr, i)
- char *cp; /* ptr to input string */
- char delimit; /* delimiter */
- char **ptr; /* left pointing to next del. or */
- /* illegal character */
- int *i; /* digit that the string represents */
+stol(char *cp, char delimit, char **ptr, int *i)
{
int c = 0; /* current char */
int n = 0; /* working copy of i */