Skip to content

Commit 94161d3

Browse files
committed
Check the return value of the gettimeofday() in 'jerry_port_get_time_zone' and 'jerry_port_get_current_time' functions.
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka [email protected]
1 parent 3de4170 commit 94161d3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

jerry-libc/target/mcu-stubs/jerry-libc-target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ int
6565
gettimeofday (void *tp __attr_unused___, /**< struct timeval */
6666
void *tzp __attr_unused___) /**< struct timezone */
6767
{
68-
return 0;
68+
return -1;
6969
} /* gettimeofday */

targets/default/jerry-port-default-date.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
3232
tz.tz_minuteswest = 0;
3333
tz.tz_dsttime = 0;
3434

35-
gettimeofday (&tv, &tz);
35+
if (gettimeofday (&tv, &tz) != 0)
36+
{
37+
return false;
38+
}
3639

3740
tz_p->offset = tz.tz_minuteswest;
3841
tz_p->daylight_saving_time = tz.tz_dsttime > 0 ? 1 : 0;
@@ -47,7 +50,10 @@ double jerry_port_get_current_time ()
4750
{
4851
struct timeval tv;
4952

50-
gettimeofday (&tv, NULL);
53+
if (gettimeofday (&tv, NULL) != 0)
54+
{
55+
return 0;
56+
}
5157

5258
return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
5359
} /* jerry_port_get_current_time */

0 commit comments

Comments
 (0)