From 649f73fd60e46e8afd6d7b902915521a8b9a01ea Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sat, 3 Sep 2022 15:40:40 +0300 Subject: [PATCH] arduino : fix bug in the Reed-Solomon code that causes crashes on some MCUs The issue was first reported here: https://github.com/ggerganov/ggwave-arduino/issues/1 We were incorrectly reading the "log" array in RS::gf::pow() function. It is surprising how this code even worked on the other microcontrollers. Probably we have been reading bogus values, so I expect the performance of the transmissions to improve after this change. --- src/reed-solomon/gf.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/reed-solomon/gf.hpp b/src/reed-solomon/gf.hpp index 04278b6..68a3b4f 100644 --- a/src/reed-solomon/gf.hpp +++ b/src/reed-solomon/gf.hpp @@ -129,7 +129,11 @@ inline uint8_t div(uint8_t x, uint8_t y){ * @param power - power * @return x^power */ inline uint8_t pow(uint8_t x, intmax_t power){ +#ifdef ARDUINO + intmax_t i = pgm_read_byte(log + x); +#else intmax_t i = log[x]; +#endif i *= power; i %= 255; if(i < 0) i = i + 255;