jsphuebner / libopeninv

Generic modules that can be used in many projects
GNU Lesser General Public License v3.0
21 stars 21 forks source link

Verify_flash_params #7

Closed streber42 closed 1 year ago

streber42 commented 1 year ago

Add bounds checking when loading params from flash. If a PARAM_NUM gets reused it can cause really hard to debug behavior/crashes.

jsphuebner commented 1 year ago

I was just going to merge this, but there is one issue: For example in stm32-sine there is a line that reads

   if (Param::Get(Param::offthrotregen) > 0)
      Param::Set(Param::offthrotregen, -Param::Get(Param::offthrotregen));

So the old, positive value is loaded, then we check if the loaded value is > 0 and if so just change the sign. With the boundary check we would have lost the users previous setting.

streber42 commented 1 year ago

Wouldn't this be fixed by setting the bounds on the param to reflect this kind of logic? If you can handle it being negative set the bounds to match?