mirror of
https://github.com/irssi/irssi.git
synced 2025-01-03 14:56:47 -05:00
Make the time duration parser stricter.
This makes /set server_reconnect_time = 10min fail instead of setting the time to 0. git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@5057 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
bb92a2dbc7
commit
c4bd1631bb
@ -811,34 +811,45 @@ int nearest_power(int num)
|
||||
int parse_time_interval(const char *time, int *msecs)
|
||||
{
|
||||
const char *desc;
|
||||
int number, sign, len, ret;
|
||||
int number, sign, len, ret, digits;
|
||||
|
||||
*msecs = 0;
|
||||
|
||||
/* max. return value is around 24 days */
|
||||
number = 0; sign = 1; ret = TRUE;
|
||||
for (;;) {
|
||||
if (*time == '-') {
|
||||
sign = -sign;
|
||||
number = 0; sign = 1; ret = TRUE; digits = FALSE;
|
||||
while (i_isspace(*time))
|
||||
time++;
|
||||
if (*time == '-') {
|
||||
sign = -sign;
|
||||
time++;
|
||||
while (i_isspace(*time))
|
||||
time++;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
for (;;) {
|
||||
if (i_isdigit(*time)) {
|
||||
number = number*10 + (*time - '0');
|
||||
time++;
|
||||
digits = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!digits)
|
||||
return FALSE;
|
||||
|
||||
/* skip punctuation */
|
||||
while (*time != '\0' && i_ispunct(*time))
|
||||
while (*time != '\0' && i_ispunct(*time) && *time != '-')
|
||||
time++;
|
||||
|
||||
/* get description */
|
||||
for (len = 0, desc = time; i_isalpha(*time); time++)
|
||||
len++;
|
||||
|
||||
while (i_isspace(*time))
|
||||
time++;
|
||||
|
||||
if (len == 0) {
|
||||
if (*time != '\0')
|
||||
return FALSE;
|
||||
*msecs += number * 1000; /* assume seconds */
|
||||
*msecs *= sign;
|
||||
return TRUE;
|
||||
@ -868,13 +879,14 @@ int parse_time_interval(const char *time, int *msecs)
|
||||
}
|
||||
|
||||
/* skip punctuation */
|
||||
while (*time != '\0' && i_ispunct(*time))
|
||||
while (*time != '\0' && i_ispunct(*time) && *time != '-')
|
||||
time++;
|
||||
|
||||
if (*time == '\0')
|
||||
break;
|
||||
|
||||
number = 0;
|
||||
digits = FALSE;
|
||||
}
|
||||
|
||||
*msecs *= sign;
|
||||
|
Loading…
Reference in New Issue
Block a user