Refactor, use NULL and not (char *)0 and similar

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2018-08-05 19:02:25 +02:00
parent 2e84a34758
commit aef7e07704
5 changed files with 44 additions and 48 deletions

View File

@ -348,7 +348,7 @@ static void CloseLogSrc(void)
break;
}
if (output_file != (FILE *)0)
if (output_file != NULL)
fflush(output_file);
}
@ -400,7 +400,7 @@ static void Terminate(void)
CloseLogSrc();
Syslog(LOG_INFO, "Kernel log daemon terminating.");
sleep(1);
if (output_file != (FILE *)0)
if (output_file != NULL)
fclose(output_file);
closelog();
#ifndef TESTING
@ -534,7 +534,7 @@ extern void Syslog(int priority, char *fmt, ...)
}
/* Handle output to a file. */
if (output_file != (FILE *)0) {
if (output_file != NULL) {
va_start(ap, fmt);
vfprintf(output_file, fmt, ap);
va_end(ap);
@ -790,11 +790,11 @@ static void LogLine(char *ptr, int len)
int sym_space;
*(line - 1) = 0; /* null terminate the address string */
value = strtoul(sym_start + 1, (char **)0, 16);
value = strtoul(sym_start + 1, NULL, 16);
*(line - 1) = '>'; /* put back delim */
symbol = LookupSymbol(value, &sym);
if (!symbol_lookup || symbol == (char *)0) {
if (!symbol_lookup || symbol == NULL) {
parse_state = PARSING_TEXT;
break;
}
@ -978,9 +978,9 @@ int main(int argc, char *argv[])
}
/* Set console logging level. */
if (log_level != (char *)0) {
if (log_level != NULL) {
if ((strlen(log_level) > 1) ||
(strchr("12345678", *log_level) == (char *)0)) {
(strchr("12345678", *log_level) == NULL)) {
fprintf(stderr, "klogd: Invalid console logging "
"level <%s> specified.\n",
log_level);
@ -1061,7 +1061,7 @@ int main(int argc, char *argv[])
if (use_output) {
if (strcmp(output, "-") == 0)
output_file = stdout;
else if ((output_file = fopen(output, "w")) == (FILE *)0) {
else if ((output_file = fopen(output, "w")) == NULL) {
fprintf(stderr, "klogd: Cannot open output file "
"%s - %s\n",
output, strerror(errno));

View File

@ -138,7 +138,7 @@
int num_syms = 0;
static int i_am_paranoid = 0;
static char vstring[12];
static struct sym_table *sym_array = (struct sym_table *)0;
static struct sym_table *sym_array = NULL;
static char *system_maps[] =
{
@ -148,7 +148,7 @@ static char *system_maps[] =
#if defined(TEST)
"./System.map",
#endif
(char *)0
NULL
};
#if defined(TEST)
@ -309,21 +309,21 @@ static char *FindSymbolFile(void)
if (debugging)
fputs("Searching for symbol map.\n", stderr);
for (mf = system_maps; *mf != (char *)0 && file == (char *)0; ++mf) {
for (mf = system_maps; *mf != NULL && file == NULL; ++mf) {
sprintf(symfile, "%s-%s", *mf, utsname.release);
if (debugging)
fprintf(stderr, "Trying %s.\n", symfile);
if ((sym_file = fopen(symfile, "r")) != (FILE *)0) {
if ((sym_file = fopen(symfile, "r")) != NULL) {
if (CheckMapVersion(symfile) == 1)
file = symfile;
fclose(sym_file);
}
if (sym_file == (FILE *)0 || file == (char *)0) {
if (sym_file == NULL || file == NULL) {
sprintf(symfile, "%s", *mf);
if (debugging)
fprintf(stderr, "Trying %s.\n", symfile);
if ((sym_file = fopen(symfile, "r")) != (FILE *)0) {
if ((sym_file = fopen(symfile, "r")) != NULL) {
if (CheckMapVersion(symfile) == 1)
file = symfile;
fclose(sym_file);
@ -480,7 +480,7 @@ static int CheckMapVersion(char *fname)
char type;
int version;
if ((sym_file = fopen(fname, "r")) != (FILE *)0) {
if ((sym_file = fopen(fname, "r")) != NULL) {
/*
* At this point a map file was successfully opened. We
* now need to search this file and look for version
@ -648,7 +648,7 @@ static void FreeSymbols(void)
/* Whack the entire array and initialize everything. */
free(sym_array);
sym_array = (struct sym_table *)0;
sym_array = NULL;
num_syms = 0;
}
@ -702,7 +702,7 @@ char *ExpandKadds(char *line, char *el)
* open for patches.
*/
if (i_am_paranoid &&
(strstr(line, "Oops:") != (char *)0) && !InitMsyms())
(strstr(line, "Oops:") != NULL) && !InitMsyms())
Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
/*
@ -710,7 +710,7 @@ char *ExpandKadds(char *line, char *el)
* messages in this line.
*/
if ((num_syms == 0) ||
(kp = strstr(line, "[<")) == (char *)0) {
(kp = strstr(line, "[<")) == NULL) {
strcpy(el, line);
return el;
}
@ -721,15 +721,15 @@ char *ExpandKadds(char *line, char *el)
*elp++ = *sl++;
/* Now poised at a kernel delimiter. */
if ((kp = strstr(sl, ">]")) == (char *)0) {
if ((kp = strstr(sl, ">]")) == NULL) {
strcpy(el, sl);
return el;
}
dlm = *kp;
strncpy(num, sl + 1, kp - sl - 1);
num[kp - sl - 1] = '\0';
value = strtoul(num, (char **)0, 16);
if ((symbol = LookupSymbol(value, &sym)) == (char *)0)
value = strtoul(num, NULL, 16);
if ((symbol = LookupSymbol(value, &sym)) == NULL)
symbol = sl;
strcat(elp, symbol);
@ -749,9 +749,9 @@ char *ExpandKadds(char *line, char *el)
strncat(elp, kp, value);
elp += value;
sl = kp + value;
if ((kp = strstr(sl, "[<")) == (char *)0)
if ((kp = strstr(sl, "[<")) == NULL)
strcat(elp, sl);
} while (kp != (char *)0);
} while (kp != NULL);
if (debugging)
fprintf(stderr, "Expanded line: %s\n", el);
@ -793,7 +793,7 @@ int main(int argc, char *argv[])
debugging = 1;
if (!InitKsyms((char *)0)) {
if (!InitKsyms(NULL)) {
fputs("ksym: Error loading system map.\n", stderr);
return 1;
}

View File

@ -129,7 +129,7 @@
#define KSYMS "/proc/kallsyms"
static int num_modules = 0;
struct Module *sym_array_modules = (struct Module *)0;
struct Module *sym_array_modules = NULL;
static int have_modules = 0;
@ -284,7 +284,7 @@ static void FreeModules(void)
}
free(sym_array_modules);
sym_array_modules = (struct Module *)0;
sym_array_modules = NULL;
num_modules = 0;
return;
}
@ -384,7 +384,7 @@ static int AddSymbol(const char *line)
return 0;
*p = '\0';
address = strtoul(line, (char **)0, 16);
address = strtoul(line, NULL, 16);
p += 3;
@ -405,11 +405,11 @@ static int AddSymbol(const char *line)
mp->sym_array = (struct sym_table *)realloc(mp->sym_array,
(mp->num_syms + 1) * sizeof(struct sym_table));
if (mp->sym_array == (struct sym_table *)0)
if (mp->sym_array == NULL)
return 0;
mp->sym_array[mp->num_syms].name = strdup(p);
if (mp->sym_array[mp->num_syms].name == (char *)0)
if (mp->sym_array[mp->num_syms].name == NULL)
return 0;
/* Stuff interesting information into the module. */

View File

@ -21,8 +21,6 @@
#include <syslog.h>
#include <unistd.h>
extern int main(int, char **);
int main(int argc, char *argv[])
{
char *nl,
@ -33,10 +31,8 @@ int main(int argc, char *argv[])
if (argc > 1) {
if ((*argv[1] == '-') && (*(argv[1] + 1) == '\0')) {
while (!feof(stdin))
if (fgets(bufr, sizeof(bufr), stdin) !=
(char *)0) {
if ((nl = strrchr(bufr, '\n')) !=
(char *)0)
if (fgets(bufr, sizeof(bufr), stdin)) {
if ((nl = strrchr(bufr, '\n')))
*nl = '\0';
syslog(LOG_INFO, "%s", bufr);
logged += strlen(bufr);

View File

@ -1076,7 +1076,7 @@ int main(int argc, char *argv[])
num_fds = getdtablesize();
logit("Allocated parts table for %d file descriptors.\n", num_fds);
if ((parts = (char **)malloc(num_fds * sizeof(char *))) ==
(char **)0) {
NULL) {
logerror("Cannot allocate memory for message parts table.");
#ifndef TESTING
if (getpid() != ppid)
@ -1085,7 +1085,7 @@ int main(int argc, char *argv[])
die(0);
}
for (i = 0; i < num_fds; ++i)
parts[i] = (char *)0;
parts[i] = NULL;
logit("Starting.\n");
init();
@ -1246,7 +1246,7 @@ int main(int argc, char *argv[])
logit("Message from stdin.\n");
memset(line, '\0', sizeof(line));
line[0] = '.';
parts[fileno(stdin)] = (char *)0;
parts[fileno(stdin)] = NULL;
i = read(fileno(stdin), line, MAXLINE);
if (i > 0) {
printchopped(LocalHostName, line, i + 1, fileno(stdin));
@ -1507,7 +1507,7 @@ void untty(void)
if (!Debug) {
i = open(_PATH_TTY, O_RDWR);
if (i >= 0) {
(void)ioctl(i, (int)TIOCNOTTY, (char *)0);
(void)ioctl(i, (int)TIOCNOTTY, NULL);
(void)close(i);
}
}
@ -1527,11 +1527,11 @@ void printchopped(const char *hname, char *msg, size_t len, int fd)
logit("Message length: %d, File descriptor: %d.\n", len, fd);
tmpline[0] = '\0';
if (parts[fd] != (char *)0) {
if (parts[fd] != NULL) {
logit("Including part from messages.\n");
strcpy(tmpline, parts[fd]);
free(parts[fd]);
parts[fd] = (char *)0;
parts[fd] = NULL;
if ((strlen(msg) + strlen(tmpline)) > MAXLINE) {
logerror("Cannot glue message parts together");
printline(hname, tmpline);
@ -1555,7 +1555,7 @@ void printchopped(const char *hname, char *msg, size_t len, int fd)
if (*p == '\0')
p++;
ptlngth = strlen(p);
if ((parts[fd] = malloc(ptlngth + 1)) == (char *)0)
if ((parts[fd] = malloc(ptlngth + 1)) == NULL)
logerror("Cannot allocate memory for message part.");
else {
strcpy(parts[fd], p);
@ -1937,7 +1937,7 @@ void fprintlog(struct filed *f, char *from, int flags, char *msg)
#ifdef SYSLOG_INET
case F_FORW_SUSP:
fwd_suspend = time((time_t *)0) - f->f_time;
fwd_suspend = time(NULL) - f->f_time;
if (fwd_suspend >= INET_SUSPEND_TIME) {
logit("\nForwarding suspension over, "
"retrying FORW ");
@ -1962,7 +1962,7 @@ void fprintlog(struct filed *f, char *from, int flags, char *msg)
*/
case F_FORW_UNKN:
logit(" %s\n", f->f_un.f_forw.f_hname);
fwd_suspend = time((time_t *)0) - f->f_time;
fwd_suspend = time(NULL) - f->f_time;
if (fwd_suspend >= INET_SUSPEND_TIME) {
logit("Forwarding suspension to unknown over, retrying\n");
memset(&hints, 0, sizeof(hints));
@ -2242,7 +2242,7 @@ void reapchild(int signo)
int saved_errno = errno;
#if defined(SYSV) && !defined(linux)
(void)signal(SIGCHLD, reapchild); /* reset signal handler -ASP */
wait((int *)0);
wait(NULL);
#else
int status;
@ -2462,7 +2462,7 @@ void init(void)
{
#ifndef TESTING
#ifndef SYSV
struct filed **nextp = (struct filed **)0;
struct filed **nextp = NULL;
#endif
#endif
struct hostent *hent;
@ -2513,7 +2513,7 @@ void init(void)
*/
nlogs = -1;
free((void *)Files);
Files = (struct filed *)0;
Files = NULL;
}
#ifdef SYSV
@ -2897,7 +2897,7 @@ void cfline(char *line, struct filed *f)
*/
f->f_type = F_FORW_UNKN;
f->f_prevcount = INET_RETRY_MAX;
f->f_time = time((time_t *)0);
f->f_time = time(NULL);
f->f_un.f_forw.f_addr = NULL;
} else {
f->f_type = F_FORW;