From a32625d62e01246fc37463a397d8c6fb1a5419f7 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 7 Dec 2024 13:17:01 +0100 Subject: [PATCH] lib/: Rename local variable Call it 'dup', which reminds that it's a strdup(3)d string. Signed-off-by: Alejandro Colomar --- lib/gshadow.c | 12 ++++++------ lib/sgetgrent.c | 12 ++++++------ lib/sgetpwent.c | 10 +++++----- lib/sgetspent.c | 12 ++++++------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/gshadow.c b/lib/gshadow.c index 86559b31a..efb046299 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -71,25 +71,25 @@ void endsgent (void) /*@observer@*//*@null@*/struct sgrp * sgetsgent(const char *s) { - static char *sgrbuf = NULL; + static char *dup = NULL; char *fields[FIELDS]; char *cp; int i; - free(sgrbuf); - sgrbuf = strdup(s); - if (sgrbuf == NULL) + free(dup); + dup = strdup(s); + if (dup == NULL) return NULL; - stpsep(sgrbuf, "\n"); + stpsep(dup, "\n"); /* * There should be exactly 4 colon separated fields. Find * all 4 of them and save the starting addresses in fields[]. */ - for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++) + for (cp = dup, i = 0; (i < FIELDS) && (NULL != cp); i++) fields[i] = strsep(&cp, ":"); /* diff --git a/lib/sgetgrent.c b/lib/sgetgrent.c index 37608344d..da5601ffc 100644 --- a/lib/sgetgrent.c +++ b/lib/sgetgrent.c @@ -68,20 +68,20 @@ list(char *s) struct group * sgetgrent(const char *s) { - static char *grpbuf = NULL; + static char *dup = NULL; static char *grpfields[NFIELDS]; static struct group grent; int i; char *cp; - free(grpbuf); - grpbuf = strdup(s); - if (grpbuf == NULL) + free(dup); + dup = strdup(s); + if (dup == NULL) return NULL; - stpsep(grpbuf, "\n"); + stpsep(dup, "\n"); - for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++) + for (cp = dup, i = 0; (i < NFIELDS) && (NULL != cp); i++) grpfields[i] = strsep(&cp, ":"); if (i < NFIELDS || streq(grpfields[2], "") || cp != NULL) { diff --git a/lib/sgetpwent.c b/lib/sgetpwent.c index e155ed0a0..61e1e4ed8 100644 --- a/lib/sgetpwent.c +++ b/lib/sgetpwent.c @@ -41,15 +41,15 @@ struct passwd * sgetpwent(const char *s) { - static char *pwdbuf = NULL; + static char *dup = NULL; static struct passwd pwent; int i; char *cp; char *fields[NFIELDS]; - free(pwdbuf); - pwdbuf = strdup(s); - if (pwdbuf == NULL) + free(dup); + dup = strdup(s); + if (dup == NULL) return NULL; /* @@ -57,7 +57,7 @@ sgetpwent(const char *s) * field. The fields are converted into NUL terminated strings. */ - for (cp = pwdbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++) + for (cp = dup, i = 0; (i < NFIELDS) && (NULL != cp); i++) fields[i] = strsep(&cp, ":"); /* something at the end, columns over shot */ diff --git a/lib/sgetspent.c b/lib/sgetspent.c index 8d58f5204..e2d247d82 100644 --- a/lib/sgetspent.c +++ b/lib/sgetspent.c @@ -39,25 +39,25 @@ struct spwd * sgetspent(const char *s) { - static char *spwbuf = NULL; + static char *dup = NULL; static struct spwd spwd; char *fields[FIELDS]; char *cp; int i; - free(spwbuf); - spwbuf = strdup(s); - if (spwbuf == NULL) + free(dup); + dup = strdup(s); + if (dup == NULL) return NULL; - stpsep(spwbuf, "\n"); + stpsep(dup, "\n"); /* * Tokenize the string into colon separated fields. Allow up to * FIELDS different fields. */ - for (cp = spwbuf, i = 0; cp != NULL && i < FIELDS; i++) + for (cp = dup, i = 0; cp != NULL && i < FIELDS; i++) fields[i] = strsep(&cp, ":"); if (i == (FIELDS - 1)) -- 2.47.2