lib/, src/: Rename some local variables

'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>
This commit is contained in:
Alejandro Colomar 2024-01-07 01:37:04 +01:00 committed by Serge Hallyn
parent f40bd94856
commit 98aefe8772
9 changed files with 45 additions and 44 deletions

View File

@ -16,13 +16,13 @@
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;

View File

@ -17,15 +17,16 @@
#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@*/) {

View File

@ -16,13 +16,13 @@
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;

View File

@ -23,17 +23,17 @@
*/
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);

View 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;

View 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;
@ -39,19 +39,19 @@
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"),

View 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)) {

View 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))
{

View 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);