]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Rename some local variables
authorAlejandro Colomar <alx@kernel.org>
Sun, 7 Jan 2024 00:37:04 +0000 (01:37 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 4 May 2024 22:22:57 +0000 (17:22 -0500)
'endptr' is appropriate internally in strtol(3) because it's a pointer
to 'end', and 'end' itself is a pointer to one-after-the-last character
of the numeric string.  In other words,

endptr == &end

However, naming the pointer whose address we pass to strtol(3)'s
'endptr' feels wrong, and causes me trouble while parsing the code; I
need to double check the number of dereferences, because something feels
wrong in my head.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/get_gid.c
lib/get_pid.c
lib/get_uid.c
lib/getgr_nam_gid.c
lib/getrange.c
lib/gettime.c
lib/limits.c
lib/prefix_flag.c
src/useradd.c

index 2c5030be37ff265b84e292bd5fcc29adbcda602e..2420137bc8b793cf4496198f7e4dd0d6da30d5a3 100644 (file)
 int
 get_gid(const char *gidstr, gid_t *gid)
 {
+       char       *end;
        long long  val;
-       char *endptr;
 
        errno = 0;
-       val = strtoll(gidstr, &endptr, 10);
+       val = strtoll(gidstr, &end, 10);
        if (   ('\0' == *gidstr)
-           || ('\0' != *endptr)
+           || ('\0' != *end)
            || (0 != errno)
            || (/*@+longintegral@*/val != (gid_t)val)/*@=longintegral@*/) {
                return -1;
index 61caa7aa2912544b578c7452081a60324e0c8537..af3f2f8ea6feb4f71b4a8ad205d58fed7ff0bf74 100644 (file)
 #include "string/sprintf.h"
 
 
-int get_pid (const char *pidstr, pid_t *pid)
+int
+get_pid(const char *pidstr, pid_t *pid)
 {
+       char       *end;
        long long  val;
-       char *endptr;
 
        errno = 0;
-       val = strtoll(pidstr, &endptr, 10);
+       val = strtoll(pidstr, &end, 10);
        if (   ('\0' == *pidstr)
-           || ('\0' != *endptr)
+           || ('\0' != *end)
            || (0 != errno)
            || (val < 1)
            || (/*@+longintegral@*/val != (pid_t)val)/*@=longintegral@*/) {
@@ -43,15 +44,15 @@ int get_pid (const char *pidstr, pid_t *pid)
  */
 int get_pidfd_from_fd(const char *pidfdstr)
 {
-       long long  val;
-       char *endptr;
-       struct stat st;
+       char         *end;
+       long long    val;
+       struct stat  st;
        dev_t proc_st_dev, proc_st_rdev;
 
        errno = 0;
-       val = strtoll(pidfdstr, &endptr, 10);
+       val = strtoll(pidfdstr, &end, 10);
        if (   ('\0' == *pidfdstr)
-           || ('\0' != *endptr)
+           || ('\0' != *end)
            || (0 != errno)
            || (val < 0)
            || (/*@+longintegral@*/val != (int)val)/*@=longintegral@*/) {
index d7169325f6671fef652bc4265bed2ed2659e480e..77fe9660a87f58d4e3f5e3b8dcc6fc54f14d88bf 100644 (file)
 int
 get_uid(const char *uidstr, uid_t *uid)
 {
+       char       *end;
        long long  val;
-       char *endptr;
 
        errno = 0;
-       val = strtoll(uidstr, &endptr, 10);
+       val = strtoll(uidstr, &end, 10);
        if (   ('\0' == *uidstr)
-           || ('\0' != *endptr)
+           || ('\0' != *end)
            || (0 != errno)
            || (/*@+longintegral@*/val != (uid_t)val)/*@=longintegral@*/) {
                return -1;
index 6d6259797b9d6d0bdeee8b96110c5140a67066e2..fd0c2171e056ff2649c9e6150a2f200deb256c7a 100644 (file)
  */
 extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname)
 {
+       char       *end;
        long long  gid;
-       char *endptr;
 
        if (NULL == grname) {
                return NULL;
        }
 
        errno = 0;
-       gid = strtoll(grname, &endptr, 10);
+       gid = strtoll(grname, &end, 10);
        if (   ('\0' != *grname)
-           && ('\0' == *endptr)
+           && ('\0' == *end)
            && (0 == errno)
            && (/*@+longintegral@*/gid == (gid_t)gid)/*@=longintegral@*/) {
                return xgetgrgid (gid);
index 8f7acee0ceb0e37588e1c00dc5a196e1af71ae4d..b2808557ca4517fe260e2893259a1f612991d5ac 100644 (file)
@@ -30,7 +30,7 @@ getrange(const char *range,
          unsigned long *min, bool *has_min,
          unsigned long *max, bool *has_max)
 {
-       char  *endptr;
+       char  *end;
 
        if (NULL == range)
                return -1;
@@ -39,32 +39,32 @@ getrange(const char *range,
        *has_max = false;
 
        if ('-' == range[0]) {
-               endptr = range + 1;
+               end = range + 1;
                goto parse_max;
        }
 
        errno = 0;
-       *min = strtoul_noneg(range, &endptr, 10);
-       if (endptr == range || 0 != errno)
+       *min = strtoul_noneg(range, &end, 10);
+       if (end == range || 0 != errno)
                return -1;
        *has_min = true;
 
-       switch (*endptr++) {
+       switch (*end++) {
        case '\0':
                *has_max = true;
                *max = *min;
                return 0;  /* <long> */
 
        case '-':
-               if ('\0' == *endptr)
+               if ('\0' == *end)
                        return 0;  /* <long>- */
 parse_max:
-               if (!isdigit(*endptr))
+               if (!isdigit(*end))
                        return -1;
 
                errno = 0;
-               *max = strtoul_noneg(endptr, &endptr, 10);
-               if ('\0' != *endptr || 0 != errno)
+               *max = strtoul_noneg(end, &end, 10);
+               if ('\0' != *end || 0 != errno)
                        return -1;
                *has_max = true;
 
index 19ebe4b3ced89e6658e9cf376749854e6215c8e2..f4ad3d79ffb14088884044fff96c098716af23ce 100644 (file)
@@ -26,7 +26,7 @@
  */
 /*@observer@*/time_t gettime (void)
 {
-       char *endptr;
+       char  *end;
        char *source_date_epoch;
        time_t fallback;
        unsigned long long epoch;
                return fallback;
 
        errno = 0;
-       epoch = strtoull_noneg(source_date_epoch, &endptr, 10);
+       epoch = strtoull_noneg(source_date_epoch, &end, 10);
        if (errno != 0) {
                fprintf (shadow_logfd,
                         _("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n"),
                         strerror(errno));
-       } else if (endptr == source_date_epoch) {
+       } else if (end == source_date_epoch) {
                fprintf (shadow_logfd,
                         _("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n"),
-                        endptr);
-       } else if (*endptr != '\0') {
+                        end);
+       } else if (*end != '\0') {
                fprintf (shadow_logfd,
                         _("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n"),
-                        endptr);
+                        end);
        } else if (epoch > ULONG_MAX) {
                fprintf (shadow_logfd,
                         _("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu\n"),
index 387a972b2a69a7b32440ea6e0a8fe3024a252938..813c0821ebb461452ef5d484be2f2fb07b859049 100644 (file)
@@ -49,7 +49,7 @@ static int setrlimit_value (unsigned int resource,
                             const char *value,
                             unsigned int multiplier)
 {
-       char           *endptr;
+       char           *end;
        long           l;
        rlim_t         limit;
        struct rlimit  rlim;
@@ -67,9 +67,9 @@ static int setrlimit_value (unsigned int resource,
                 * work with the limit string parser as is anyway)
                 */
                errno = 0;
-               l = strtol(value, &endptr, 10);
+               l = strtol(value, &end, 10);
 
-               if (value == endptr || errno != 0)
+               if (value == end || errno != 0)
                        return 0;  // FIXME: We could instead throw an error, though.
 
                if (__builtin_mul_overflow(l, multiplier, &limit)) {
index d42657d5b7c84824997c97b17d51b35450ceb6a9..bba7102b82e8b985c6e623874e7e14d72a781803 100644 (file)
@@ -334,9 +334,9 @@ extern void prefix_endgrent(void)
 
 extern struct group *prefix_getgr_nam_gid(const char *grname)
 {
-       long long  gid;
-       char *endptr;
-       struct group *g;
+       char          *end;
+       long long     gid;
+       struct group  *g;
 
        if (NULL == grname) {
                return NULL;
@@ -346,9 +346,9 @@ extern struct group *prefix_getgr_nam_gid(const char *grname)
                return getgr_nam_gid(grname);
 
        errno = 0;
-       gid = strtoll(grname, &endptr, 10);
+       gid = strtoll(grname, &end, 10);
        if (   ('\0' != *grname)
-           && ('\0' == *endptr)
+           && ('\0' == *end)
            && (0 == errno)
            && (gid == (gid_t)gid))
        {
index ec21814c91c689dc49e5f00984565321b48d091a..88d8ab7f140a49cc58f5a00d463df75501202973 100644 (file)
@@ -857,14 +857,14 @@ static int get_groups (char *list)
  */
 static struct group * get_local_group(char * grp_name)
 {
+       char  *end;
        const struct group *grp;
        struct group *result_grp = NULL;
        long long  gid;
-       char *endptr;
 
-       gid = strtoll (grp_name, &endptr, 10);
+       gid = strtoll(grp_name, &end, 10);
        if (   ('\0' != *grp_name)
-               && ('\0' == *endptr)
+               && ('\0' == *end)
                && (ERANGE != errno)
                && (gid == (gid_t)gid)) {
                grp = gr_locate_gid (gid);