Call NULL by its name

In variadic functions we still do the cast.  In POSIX, it's not
necessary, since NULL is required to be of type 'void *', and 'void *'
is guaranteed to have the same alignment and representation as 'char *'.
However, since ISO C still doesn't mandate that, and moreover they're
doing dubious stuff by adding nullptr, let's be on the cautious side.
Also, C++ requires that NULL is _not_ 'void *', but either plain 0 or
some magic stuff.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2023-02-01 02:50:14 +01:00
committed by Serge Hallyn
parent 1482224c54
commit 62172f6fb5
31 changed files with 84 additions and 84 deletions

View File

@ -112,7 +112,7 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp)
_exit (126);
}
(void) execl (PASSWD_PROGRAM, PASSWD_PROGRAM, pw->pw_name, (char *) 0);
(void) execl (PASSWD_PROGRAM, PASSWD_PROGRAM, pw->pw_name, (char *) NULL);
err = errno;
perror ("Can't execute " PASSWD_PROGRAM);
_exit ((ENOENT == err) ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
@ -139,7 +139,7 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp)
void agecheck (/*@null@*/const struct spwd *sp)
{
long now = (long) time ((time_t *) 0) / SCALE;
long now = (long) time(NULL) / SCALE;
long remain;
if (NULL == sp) {

View File

@ -24,7 +24,7 @@ void pw_entry (const char *name, struct passwd *pwent)
struct spwd *spwd;
if (!(passwd = getpwnam (name))) { /* local, no need for xgetpwnam */
pwent->pw_name = (char *) 0;
pwent->pw_name = NULL;
return;
} else {
pwent->pw_name = xstrdup (passwd->pw_name);

View File

@ -41,7 +41,7 @@ static const char *const forbid[] = {
"PATH=",
"SHELL=",
"SHLIB_PATH=",
(char *) 0
NULL
};
/* these are allowed, but with no slashes inside
@ -50,7 +50,7 @@ static const char *const noslash[] = {
"LANG=",
"LANGUAGE=",
"LC_", /* anything with the LC_ prefix */
(char *) 0
NULL
};
/*

View File

@ -40,7 +40,7 @@ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp)
{
long now;
now = (long) time ((time_t *) 0) / SCALE;
now = (long) time(NULL) / SCALE;
if (NULL == sp) {
return 0;

View File

@ -33,7 +33,7 @@
* pointer if it is present.
*/
for (i = 0; list[i] != (char *) 0; i++) {
for (i = 0; list[i] != NULL; i++) {
if (strcmp (list[i], member) == 0) {
return list;
}
@ -52,12 +52,12 @@
* is returned to the invoker.
*/
for (i = 0; list[i] != (char *) 0; i++) {
for (i = 0; list[i] != NULL; i++) {
tmp[i] = list[i];
}
tmp[i] = xstrdup (member);
tmp[i+1] = (char *) 0;
tmp[i+1] = NULL;
return tmp;
}
@ -83,7 +83,7 @@
* pointer if it is not present.
*/
for (i = j = 0; list[i] != (char *) 0; i++) {
for (i = j = 0; list[i] != NULL; i++) {
if (strcmp (list[i], member) != 0) {
j++;
}
@ -106,14 +106,14 @@
* is returned to the invoker.
*/
for (i = j = 0; list[i] != (char *) 0; i++) {
for (i = j = 0; list[i] != NULL; i++) {
if (strcmp (list[i], member) != 0) {
tmp[j] = list[i];
j++;
}
}
tmp[j] = (char *) 0;
tmp[j] = NULL;
return tmp;
}
@ -142,7 +142,7 @@
list++;
}
tmp[i] = (char *) 0;
tmp[i] = NULL;
return tmp;
}
@ -217,7 +217,7 @@ bool is_on_list (char *const *list, const char *member)
*/
if ('\0' == *members) {
*array = (char *) 0;
*array = NULL;
free (members);
return array;
}
@ -235,7 +235,7 @@ bool is_on_list (char *const *list, const char *member)
cp2++;
cp = cp2;
} else {
array[i + 1] = (char *) 0;
array[i + 1] = NULL;
break;
}
}

View File

@ -122,7 +122,7 @@ void login_prompt (const char *prompt, char *name, int namesize)
int envc;
for (envc = 0; envc < MAX_ENV; envc++) {
nvar = strtok ((0 != envc) ? (char *) 0 : cp, " \t,");
nvar = strtok ((0 != envc) ? NULL : cp, " \t,");
if (NULL == nvar) {
break;
}

View File

@ -26,7 +26,7 @@ void passwd_check (const char *user, const char *passwd, unused const char *prog
if (NULL != sp) {
passwd = sp->sp_pwdp;
}
if (pw_auth (passwd, user, PW_LOGIN, (char *) 0) != 0) {
if (pw_auth (passwd, user, PW_LOGIN, NULL) != 0) {
SYSLOG ((LOG_WARN, "incorrect password for `%s'", user));
(void) sleep (1);
fprintf (log_get_logfd(), _("Incorrect password for %s.\n"), user);

View File

@ -33,7 +33,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
char arg0[1024];
int err;
if (file == (char *) 0) {
if (file == NULL) {
errno = EINVAL;
return errno;
}
@ -44,7 +44,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
* that. So, we determine the 0'th entry only if they
* don't want to tell us what it is themselves.
*/
if (arg == (char *) 0) {
if (arg == NULL) {
(void) snprintf (arg0, sizeof arg0, "-%s", Basename (file));
arg0[sizeof arg0 - 1] = '\0';
arg = arg0;
@ -55,7 +55,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
* able to figure out what we are up to without too much
* grief.
*/
(void) execle (file, arg, (char *) 0, envp);
(void) execle (file, arg, (char *) NULL, envp);
err = errno;
if (access (file, R_OK|X_OK) == 0) {
@ -63,7 +63,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
* Assume this is a shell script (with no shebang).
* Interpret it with /bin/sh
*/
(void) execle (SHELL, "sh", "-", file, (char *)0, envp);
(void) execle (SHELL, "sh", "-", file, (char *) NULL, envp);
err = errno;
}

View File

@ -64,7 +64,7 @@ void sulog (const char *tty, bool success, const char *oldname, const char *name
/* Do not return if the group permission were raised. */
exit (EXIT_FAILURE);
}
if (fp == (FILE *) 0) {
if (fp == NULL) {
return; /* can't open or create logfile */
}