Commit 868d585aced5457218b3443398d08594d9c3ba6d
1 parent
c80f84e3
Avoid crash on NULL timers.
This is a rework of Stefan Weil proposed patch. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3283 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
8 additions
and
10 deletions
hw/m48t59.c
... | ... | @@ -161,10 +161,9 @@ static void set_alarm (m48t59_t *NVRAM, struct tm *tm) |
161 | 161 | NVRAM->alarm = mktime(tm); |
162 | 162 | if (NVRAM->alrm_timer != NULL) { |
163 | 163 | qemu_del_timer(NVRAM->alrm_timer); |
164 | - NVRAM->alrm_timer = NULL; | |
164 | + if (NVRAM->alarm - time(NULL) > 0) | |
165 | + qemu_mod_timer(NVRAM->alrm_timer, NVRAM->alarm * 1000); | |
165 | 166 | } |
166 | - if (NVRAM->alarm - time(NULL) > 0) | |
167 | - qemu_mod_timer(NVRAM->alrm_timer, NVRAM->alarm * 1000); | |
168 | 167 | } |
169 | 168 | |
170 | 169 | /* Watchdog management */ |
... | ... | @@ -188,15 +187,14 @@ static void set_up_watchdog (m48t59_t *NVRAM, uint8_t value) |
188 | 187 | { |
189 | 188 | uint64_t interval; /* in 1/16 seconds */ |
190 | 189 | |
190 | + NVRAM->buffer[0x1FF0] &= ~0x80; | |
191 | 191 | if (NVRAM->wd_timer != NULL) { |
192 | 192 | qemu_del_timer(NVRAM->wd_timer); |
193 | - NVRAM->wd_timer = NULL; | |
194 | - } | |
195 | - NVRAM->buffer[0x1FF0] &= ~0x80; | |
196 | - if (value != 0) { | |
197 | - interval = (1 << (2 * (value & 0x03))) * ((value >> 2) & 0x1F); | |
198 | - qemu_mod_timer(NVRAM->wd_timer, ((uint64_t)time(NULL) * 1000) + | |
199 | - ((interval * 1000) >> 4)); | |
193 | + if (value != 0) { | |
194 | + interval = (1 << (2 * (value & 0x03))) * ((value >> 2) & 0x1F); | |
195 | + qemu_mod_timer(NVRAM->wd_timer, ((uint64_t)time(NULL) * 1000) + | |
196 | + ((interval * 1000) >> 4)); | |
197 | + } | |
200 | 198 | } |
201 | 199 | } |
202 | 200 | ... | ... |