Skip to content
Snippets Groups Projects
Commit cac0bcf3 authored by rahix's avatar rahix
Browse files

Merge 'faulty unsigned comparisons'

Fix faulty error handling due to always-false unsigned comparisons.
`-Wtype-limits` revealed three errors in the firmware:

    ../pycardium/modules/sys_leds.c: In function 'mp_leds_get_rocket':
    ../pycardium/modules/sys_leds.c:207:10: warning: comparison is
                always false due to limited range of data type [-Wtype-limits]
      207 |  if (ret == -EINVAL) {
          |          ^~


    ../pycardium/mphalport.c: In function 'mp_hal_set_interrupt_char':
    ../pycardium/mphalport.c:115:8: warning: comparison is always true
                due to limited range of data type [-Wtype-limits]
      115 |  if (c != -1) {
          |        ^~

    ../epicardium/modules/bhi.c: In function 'epic_bhi160_enable_sensor':
    ../epicardium/modules/bhi.c:134:12: warning: comparison is always
                false due to limited range of data type [-Wtype-limits]
      134 |  if (vs_id < 0) {
          |            ^
    ../epicardium/modules/bhi.c: In function 'epic_bhi160_disable_sensor':
    ../epicardium/modules/bhi.c:191:12: warning: comparison is always
                false due to limited range of data type [-Wtype-limits]
      191 |  if (vs_id < 0) {
          |            ^

Note that on the target platform `char` and `enum`s are unsigned.  The
compiler has probably removed all of these `if`s so far because the
conditions were determined to always be false.

See merge request !357
parents 87bccda8 d189f48e
No related branches found
No related tags found
1 merge request!357fix(bhi, leds): fixed faulty error handling due to always-false unsigned comparisons
Pipeline #4263 passed
...@@ -131,7 +131,7 @@ int epic_bhi160_enable_sensor( ...@@ -131,7 +131,7 @@ int epic_bhi160_enable_sensor(
int result = 0; int result = 0;
bhy_virtual_sensor_t vs_id = bhi160_lookup_vs_id(sensor_type); bhy_virtual_sensor_t vs_id = bhi160_lookup_vs_id(sensor_type);
if (vs_id < 0) { if (vs_id == (bhy_virtual_sensor_t)-1) {
return -ENODEV; return -ENODEV;
} }
...@@ -188,7 +188,7 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type) ...@@ -188,7 +188,7 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type)
int result = 0; int result = 0;
bhy_virtual_sensor_t vs_id = bhi160_lookup_vs_id(sensor_type); bhy_virtual_sensor_t vs_id = bhi160_lookup_vs_id(sensor_type);
if (vs_id < 0) { if (vs_id == (bhy_virtual_sensor_t)-1) {
return -ENODEV; return -ENODEV;
} }
......
...@@ -202,8 +202,8 @@ static MP_DEFINE_CONST_FUN_OBJ_2(leds_set_rocket_obj, mp_leds_set_rocket); ...@@ -202,8 +202,8 @@ static MP_DEFINE_CONST_FUN_OBJ_2(leds_set_rocket_obj, mp_leds_set_rocket);
static mp_obj_t mp_leds_get_rocket(mp_obj_t led_in) static mp_obj_t mp_leds_get_rocket(mp_obj_t led_in)
{ {
int led = mp_obj_get_int(led_in); int led = mp_obj_get_int(led_in);
uint8_t ret = epic_leds_get_rocket(led); int ret = epic_leds_get_rocket(led);
if (ret == -EINVAL) { if (ret == -EINVAL) {
mp_raise_ValueError( mp_raise_ValueError(
"invalid value: maybe the led does not exists" "invalid value: maybe the led does not exists"
......
...@@ -112,7 +112,7 @@ void epic_isr_ctrl_c(void) ...@@ -112,7 +112,7 @@ void epic_isr_ctrl_c(void)
void mp_hal_set_interrupt_char(char c) void mp_hal_set_interrupt_char(char c)
{ {
if (c != -1) { if (c != '\xFF') {
mp_obj_exception_clear_traceback( mp_obj_exception_clear_traceback(
MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment