lib/, src/: getlong(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-01-05 16:54:55 -06:00
committed by Serge Hallyn
parent 173231a8ff
commit 2d581cb337
14 changed files with 56 additions and 58 deletions
+3 -4
View File
@@ -245,7 +245,7 @@ int getdef_num (const char *item, int dflt)
return dflt;
}
if ( (getlong (d->value, &val) == 0)
if ( (getlong(d->value, &val) == -1)
|| (val > INT_MAX)
|| (val < -1)) {
fprintf (shadow_logfd,
@@ -280,7 +280,7 @@ unsigned int getdef_unum (const char *item, unsigned int dflt)
return dflt;
}
if ( (getlong (d->value, &val) == 0)
if ( (getlong(d->value, &val) == -1)
|| (val < 0)
|| (val > INT_MAX)) {
fprintf (shadow_logfd,
@@ -315,8 +315,7 @@ long getdef_long (const char *item, long dflt)
return dflt;
}
if ( (getlong (d->value, &val) == 0)
|| (val < -1)) {
if (getlong(d->value, &val) == -1 || val < -1) {
fprintf (shadow_logfd,
_("configuration error - cannot parse %s value: '%s'"),
item, d->value);
+10 -10
View File
@@ -4,33 +4,33 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <config.h>
#ident "$Id$"
#include <stdlib.h>
#include <errno.h>
#include "prototypes.h"
/*
* getlong - extract a long integer provided by the numstr string in *result
*
* It supports decimal, hexadecimal or octal representations.
*
* Returns 0 on failure, 1 on success.
*/
int getlong (const char *numstr, /*@out@*/long *result)
int
getlong(const char *numstr, /*@out@*/long *result)
{
long val;
char *endptr;
char *endptr;
long val;
errno = 0;
val = strtol(numstr, &endptr, 0);
if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno)) {
return 0;
}
if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno))
return -1;
*result = val;
return 1;
return 0;
}
+3 -4
View File
@@ -89,7 +89,7 @@ static int set_prio (const char *value)
{
long prio;
if ( (getlong (value, &prio) == 0)
if ( (getlong(value, &prio) == -1)
|| (prio != (int) prio)) {
return 0;
}
@@ -482,7 +482,7 @@ void setup_limits (const struct passwd *info)
if (strncmp (cp, "pri=", 4) == 0) {
long inc;
if ( (getlong (cp + 4, &inc) == 1)
if ( (getlong(cp + 4, &inc) == 0)
&& (inc >= -20) && (inc <= 20)) {
errno = 0;
if ( (nice (inc) != -1)
@@ -500,8 +500,7 @@ void setup_limits (const struct passwd *info)
}
if (strncmp (cp, "ulimit=", 7) == 0) {
long blocks;
if ( (getlong (cp + 7, &blocks) == 0)
if ( (getlong(cp + 7, &blocks) == -1)
|| (blocks != (int) blocks)
|| (set_filesize_limit (blocks) != 0)) {
SYSLOG ((LOG_WARN,
+6 -6
View File
@@ -92,7 +92,7 @@ struct spwd *sgetspent (const char *string)
if (fields[2][0] == '\0') {
spwd.sp_lstchg = -1;
} else if ( (getlong (fields[2], &spwd.sp_lstchg) == 0)
} else if ( (getlong(fields[2], &spwd.sp_lstchg) == -1)
|| (spwd.sp_lstchg < 0)) {
return 0;
}
@@ -103,7 +103,7 @@ struct spwd *sgetspent (const char *string)
if (fields[3][0] == '\0') {
spwd.sp_min = -1;
} else if ( (getlong (fields[3], &spwd.sp_min) == 0)
} else if ( (getlong(fields[3], &spwd.sp_min) == -1)
|| (spwd.sp_min < 0)) {
return 0;
}
@@ -114,7 +114,7 @@ struct spwd *sgetspent (const char *string)
if (fields[4][0] == '\0') {
spwd.sp_max = -1;
} else if ( (getlong (fields[4], &spwd.sp_max) == 0)
} else if ( (getlong(fields[4], &spwd.sp_max) == -1)
|| (spwd.sp_max < 0)) {
return 0;
}
@@ -139,7 +139,7 @@ struct spwd *sgetspent (const char *string)
if (fields[5][0] == '\0') {
spwd.sp_warn = -1;
} else if ( (getlong (fields[5], &spwd.sp_warn) == 0)
} else if ( (getlong(fields[5], &spwd.sp_warn) == -1)
|| (spwd.sp_warn < 0)) {
return 0;
}
@@ -151,7 +151,7 @@ struct spwd *sgetspent (const char *string)
if (fields[6][0] == '\0') {
spwd.sp_inact = -1;
} else if ( (getlong (fields[6], &spwd.sp_inact) == 0)
} else if ( (getlong(fields[6], &spwd.sp_inact) == -1)
|| (spwd.sp_inact < 0)) {
return 0;
}
@@ -163,7 +163,7 @@ struct spwd *sgetspent (const char *string)
if (fields[7][0] == '\0') {
spwd.sp_expire = -1;
} else if ( (getlong (fields[7], &spwd.sp_expire) == 0)
} else if ( (getlong(fields[7], &spwd.sp_expire) == -1)
|| (spwd.sp_expire < 0)) {
return 0;
}
+6 -6
View File
@@ -166,7 +166,7 @@ static struct spwd *my_sgetspent (const char *string)
if (fields[2][0] == '\0') {
spwd.sp_lstchg = -1;
} else {
if (getlong (fields[2], &spwd.sp_lstchg) == 0) {
if (getlong(fields[2], &spwd.sp_lstchg) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_lstchg = -1;
@@ -185,7 +185,7 @@ static struct spwd *my_sgetspent (const char *string)
if (fields[3][0] == '\0') {
spwd.sp_min = -1;
} else {
if (getlong (fields[3], &spwd.sp_min) == 0) {
if (getlong(fields[3], &spwd.sp_min) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_min = -1;
@@ -206,7 +206,7 @@ static struct spwd *my_sgetspent (const char *string)
if (fields[4][0] == '\0') {
spwd.sp_max = -1;
} else {
if (getlong (fields[4], &spwd.sp_max) == 0) {
if (getlong(fields[4], &spwd.sp_max) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_max = -1;
@@ -239,7 +239,7 @@ static struct spwd *my_sgetspent (const char *string)
if (fields[5][0] == '\0') {
spwd.sp_warn = -1;
} else {
if (getlong (fields[5], &spwd.sp_warn) == 0) {
if (getlong(fields[5], &spwd.sp_warn) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_warn = -1;
@@ -261,7 +261,7 @@ static struct spwd *my_sgetspent (const char *string)
if (fields[6][0] == '\0') {
spwd.sp_inact = -1;
} else {
if (getlong (fields[6], &spwd.sp_inact) == 0) {
if (getlong(fields[6], &spwd.sp_inact) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_inact = -1;
@@ -283,7 +283,7 @@ static struct spwd *my_sgetspent (const char *string)
if (fields[7][0] == '\0') {
spwd.sp_expire = -1;
} else {
if (getlong (fields[7], &spwd.sp_expire) == 0) {
if (getlong(fields[7], &spwd.sp_expire) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_expire = -1;
+1 -1
View File
@@ -62,7 +62,7 @@ long strtoday (const char *str)
}
if (isnum) {
long retdate;
if (getlong (str, &retdate) == 0) {
if (getlong(str, &retdate) == -1) {
return -2;
}
return retdate;