diff options
author | Wesley Aptekar-Cassels <me@wesleyac.com> | 2023-12-06 21:49:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-06 21:49:58 -0500 |
commit | 63d6bc6aa0ddf4cc1ce1918ef7650852a25e581b (patch) | |
tree | 2bde14499eb063dbb367c2249ff73dd3e182bc2e | |
parent | 1b90a4a07a591c6f074eacb0f0dae9cabc7e0f90 (diff) | |
parent | 8206f37fcfc53e27b2ce4801bbaab1a99d48a308 (diff) | |
download | Sensor-Watch-63d6bc6aa0ddf4cc1ce1918ef7650852a25e581b.tar.gz Sensor-Watch-63d6bc6aa0ddf4cc1ce1918ef7650852a25e581b.tar.bz2 Sensor-Watch-63d6bc6aa0ddf4cc1ce1918ef7650852a25e581b.zip |
Merge pull request #336 from theAlexes/theAlexes/sanitize
fix undefined behavior found by clang's sanitize
The compiler isn't completely assured of the possible range of this variable. Probably harmless, but it clears up a clang sanitize error.
-rw-r--r-- | watch-library/hardware/watch/watch_rtc.c | 4 | ||||
-rw-r--r-- | watch-library/simulator/watch/watch_rtc.c | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/watch-library/hardware/watch/watch_rtc.c b/watch-library/hardware/watch/watch_rtc.c index 881e2575..93cb9f1c 100644 --- a/watch-library/hardware/watch/watch_rtc.c +++ b/watch-library/hardware/watch/watch_rtc.c @@ -84,7 +84,7 @@ void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequen if (__builtin_popcount(frequency) != 1) return; // this left-justifies the period in a 32-bit integer. - uint32_t tmp = frequency << 24; + uint32_t tmp = (frequency & 0xFF) << 24; // now we can count the leading zeroes to get the value we need. // 0x01 (1 Hz) will have 7 leading zeros for PER7. 0xF0 (128 Hz) will have no leading zeroes for PER0. uint8_t per_n = __builtin_clz(tmp); @@ -99,7 +99,7 @@ void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequen void watch_rtc_disable_periodic_callback(uint8_t frequency) { if (__builtin_popcount(frequency) != 1) return; - uint8_t per_n = __builtin_clz(frequency << 24); + uint8_t per_n = __builtin_clz((frequency & 0xFF) << 24); RTC->MODE2.INTENCLR.reg = 1 << per_n; } diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c index f6279eed..2bb6074c 100644 --- a/watch-library/simulator/watch/watch_rtc.c +++ b/watch-library/simulator/watch/watch_rtc.c @@ -92,7 +92,7 @@ void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequen if (__builtin_popcount(frequency) != 1) return; // this left-justifies the period in a 32-bit integer. - uint32_t tmp = frequency << 24; + uint32_t tmp = (frequency & 0xFF) << 24; // now we can count the leading zeroes to get the value we need. // 0x01 (1 Hz) will have 7 leading zeros for PER7. 0xF0 (128 Hz) will have no leading zeroes for PER0. uint8_t per_n = __builtin_clz(tmp); @@ -105,7 +105,7 @@ void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequen void watch_rtc_disable_periodic_callback(uint8_t frequency) { if (__builtin_popcount(frequency) != 1) return; - uint8_t per_n = __builtin_clz(frequency << 24); + uint8_t per_n = __builtin_clz((frequency & 0xFF) << 24); if (tick_callbacks[per_n] != -1) { emscripten_clear_interval(tick_callbacks[per_n]); tick_callbacks[per_n] = -1; |