Page 1 of 1

curious about why an almost equivalent C code can avoid LoadProhibited error

Posted: Tue Nov 08, 2022 5:04 pm
by TsXor-V
```c
STATIC mp_int_t getuwidth(mp_int_t cord) {
mp_int_t uw = 0;
switch (chrtype(cord)) {
case 0: uw = 1;
break;
case 1: uw = 1;
break;
case 2: uw = 2;
break;
case 3: uw = 2;
break;
case 4: uw = 2;
break;
}
return uw;
}
```
After being executed for 20+ time, it will cause LoadProhibited error.

```c
STATIC mp_int_t getuwidth(mp_int_t cord) {
if (chrtype((uint32_t)cord) <= 1) {
return 1;
} else {
return 2;
}
}
```
But this have no such problem, why?

Re: curious about why an almost equivalent C code can avoid LoadProhibited error

Posted: Thu Nov 10, 2022 7:09 pm
by cruvus
In most cases this is a sign of a buffer overflow or some screwup with an interrupt handler or a similar problem in the rest(!) of your code. Take a detailed look at the core dump.
If you change the source, even if it is equivalent, the resulting assembler code might be longer or shorter or quicker or slower. This can dig up or hide problems that were there all along (and not in the code you changed).

Re: curious about why an almost equivalent C code can avoid LoadProhibited error

Posted: Thu Nov 10, 2022 8:43 pm
by chegewara