diff options
| author | Krzysztof Adamski <k@japko.eu> | 2021-06-13 10:27:45 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2021-06-15 00:06:26 +1000 |
| commit | e7f7094ef60d91c89d05d2b006f2eb80fff3efd6 (patch) | |
| tree | 6b11fdf22da0b7684ae8375ef7144f88cea05cc8 | |
| parent | 66115a37444350b166384ae8be95639aef5a5af4 (diff) | |
rp2/machine_rtc: Check return value from rtc_set_datetime.
The rtc_set_datetime() from pico-sdk will validate the values in the
datetime_t structure and refuse to set the time if they aren't valid. It
makes sense to raise an exception if this happens instead of failing
silently which might be confusing (as an example, see:
https://github.com/micropython/micropython/pull/6928#issuecomment-860166044
).
| -rw-r--r-- | ports/rp2/machine_rtc.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/ports/rp2/machine_rtc.c b/ports/rp2/machine_rtc.c index 8ead51af1..797bee5ed 100644 --- a/ports/rp2/machine_rtc.c +++ b/ports/rp2/machine_rtc.c @@ -100,7 +100,9 @@ STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { .sec = mp_obj_get_int(items[6]), }; - rtc_set_datetime(&t); + if (!rtc_set_datetime(&t)) { + mp_raise_OSError(MP_EINVAL); + } } return mp_const_none; |
