Added error handling for time0 string format
This commit is contained in:
parent
9f86dbfefe
commit
dc57eaf155
@ -2781,7 +2781,7 @@ static int parse_line_formatted(const char *context, int num_params, char *param
|
||||
} else if (!strcmp(params[0], "clock")) {
|
||||
const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
|
||||
char wday[4], mon[4];
|
||||
int year;
|
||||
int n, year;
|
||||
struct tm tm_time;
|
||||
for (i=1; i<num_params; i++) {
|
||||
if (!strncmp(params[i], "sync=", 5)) {
|
||||
@ -2799,11 +2799,15 @@ static int parse_line_formatted(const char *context, int num_params, char *param
|
||||
else if (!strncmp(params[i], "time0=", 6)) {
|
||||
if (isalpha(params[i][6])) {
|
||||
memset(&tm_time, 0, sizeof(tm_time));
|
||||
sscanf(¶ms[i][6], "%3s %3s%3d %2d:%2d:%2d %d", wday, mon, &tm_time.tm_mday,
|
||||
&tm_time.tm_hour, &tm_time.tm_min, &tm_time.tm_sec, &year);
|
||||
tm_time.tm_mon = 12 - (strlen(strstr(months, mon)) / 4);
|
||||
tm_time.tm_year = year - 1900;
|
||||
SIM->get_param_num(BXPN_CLOCK_TIME0)->set(mktime(&tm_time));
|
||||
n = sscanf(¶ms[i][6], "%3s %3s%3d %2d:%2d:%2d %d", wday, mon, &tm_time.tm_mday,
|
||||
&tm_time.tm_hour, &tm_time.tm_min, &tm_time.tm_sec, &year);
|
||||
if ((n == 7) && (year >= 1980) && (strstr(months, mon) != NULL)) {
|
||||
tm_time.tm_year = year - 1900;
|
||||
tm_time.tm_mon = 12 - (strlen(strstr(months, mon)) / 4);
|
||||
SIM->get_param_num(BXPN_CLOCK_TIME0)->set(mktime(&tm_time));
|
||||
} else {
|
||||
PARSE_ERR(("%s: time0 string format malformed.", context));
|
||||
}
|
||||
} else {
|
||||
SIM->get_param_num(BXPN_CLOCK_TIME0)->set(atoi(¶ms[i][6]));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user