forked from PsychoticNinja/irssi
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)
|
int parse_time_interval(const char *time, int *msecs)
|
||||||
{
|
{
|
||||||
const char *desc;
|
const char *desc;
|
||||||
int number, sign, len, ret;
|
int number, sign, len, ret, digits;
|
||||||
|
|
||||||
*msecs = 0;
|
*msecs = 0;
|
||||||
|
|
||||||
/* max. return value is around 24 days */
|
/* max. return value is around 24 days */
|
||||||
number = 0; sign = 1; ret = TRUE;
|
number = 0; sign = 1; ret = TRUE; digits = FALSE;
|
||||||
for (;;) {
|
while (i_isspace(*time))
|
||||||
if (*time == '-') {
|
time++;
|
||||||
sign = -sign;
|
if (*time == '-') {
|
||||||
|
sign = -sign;
|
||||||
|
time++;
|
||||||
|
while (i_isspace(*time))
|
||||||
time++;
|
time++;
|
||||||
continue;
|
}
|
||||||
}
|
for (;;) {
|
||||||
|
|
||||||
if (i_isdigit(*time)) {
|
if (i_isdigit(*time)) {
|
||||||
number = number*10 + (*time - '0');
|
number = number*10 + (*time - '0');
|
||||||
time++;
|
time++;
|
||||||
|
digits = TRUE;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!digits)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
/* skip punctuation */
|
/* skip punctuation */
|
||||||
while (*time != '\0' && i_ispunct(*time))
|
while (*time != '\0' && i_ispunct(*time) && *time != '-')
|
||||||
time++;
|
time++;
|
||||||
|
|
||||||
/* get description */
|
/* get description */
|
||||||
for (len = 0, desc = time; i_isalpha(*time); time++)
|
for (len = 0, desc = time; i_isalpha(*time); time++)
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
|
while (i_isspace(*time))
|
||||||
|
time++;
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
|
if (*time != '\0')
|
||||||
|
return FALSE;
|
||||||
*msecs += number * 1000; /* assume seconds */
|
*msecs += number * 1000; /* assume seconds */
|
||||||
*msecs *= sign;
|
*msecs *= sign;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -868,13 +879,14 @@ int parse_time_interval(const char *time, int *msecs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* skip punctuation */
|
/* skip punctuation */
|
||||||
while (*time != '\0' && i_ispunct(*time))
|
while (*time != '\0' && i_ispunct(*time) && *time != '-')
|
||||||
time++;
|
time++;
|
||||||
|
|
||||||
if (*time == '\0')
|
if (*time == '\0')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
number = 0;
|
number = 0;
|
||||||
|
digits = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
*msecs *= sign;
|
*msecs *= sign;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user