valid_temp_time: style fixes

This commit is contained in:
Ed Kellett 2022-03-06 16:44:45 +00:00
parent 2644dcd166
commit 492d560ee1

View file

@ -686,42 +686,43 @@ valid_temp_time(const char *p)
{ {
time_t result = 0; time_t result = 0;
long current = 0; long current = 0;
char *ch = strdup(p), *och;
while (*ch) { while (*p) {
och = ch; char *endp;
current = strtol(ch, &ch, 10);
errno = 0;
current = strtol(p, &endp, 10);
if (errno == ERANGE) if (errno == ERANGE)
return -1; return -1;
if (och == ch) if (endp == p)
/* No numbers were given so return invalid */
return -1; return -1;
if (current) {
switch (*ch) { switch (*endp) {
case '\0': /* No unit was given so send it back as minutes */ case '\0': /* No unit was given so send it back as minutes */
case 'm': case 'm':
result += (current * 60); result += current * 60;
break; break;
case 'h': case 'h':
result += (current * 3600); result += current * 3600;
break; break;
case 'd': case 'd':
result += (current * 86400); result += current * 86400;
break; break;
case 'w': case 'w':
result += (current * 604800); result += current * 604800;
break; break;
default: default:
/* Bad time unit was given */
return -1; return -1;
} }
if (*ch++ == '\0')
if (*endp == '\0')
break; break;
p = endp + 1;
} }
}
if(result > (60 * 60 * 24 * 7 * 52)) return MIN(result, 60 * 60 * 24 * 7 * 52);
result = (60 * 60 * 24 * 7 * 52);
return result;
} }
/* Propagated bans are expired elsewhere. */ /* Propagated bans are expired elsewhere. */