mirror of https://gitee.com/openkylin/qemu.git
qemu_timedate_diff() shouldn't modify its argument.
The caller of qemu_timedate_diff() does not expect that tm it passes to the function will be modified, but mktime() is destructive and modifies its argument. Pass a copy of tm to it and set tm_isdst so that mktime() will not rely on it since its value may be outdated. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
47113ab6b8
commit
f54c556c08
7
vl.c
7
vl.c
|
@ -460,8 +460,11 @@ int qemu_timedate_diff(struct tm *tm)
|
||||||
if (rtc_date_offset == -1)
|
if (rtc_date_offset == -1)
|
||||||
if (rtc_utc)
|
if (rtc_utc)
|
||||||
seconds = mktimegm(tm);
|
seconds = mktimegm(tm);
|
||||||
else
|
else {
|
||||||
seconds = mktime(tm);
|
struct tm tmp = *tm;
|
||||||
|
tmp.tm_isdst = -1; /* use timezone to figure it out */
|
||||||
|
seconds = mktime(&tmp);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
seconds = mktimegm(tm) + rtc_date_offset;
|
seconds = mktimegm(tm) + rtc_date_offset;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue