Commit 08146d9
committed
Fix undefined behavior caused by mismatched parameter types
When using 'make ENABLE_UBSAN=1 check CC=clang', the following error is
observed:
src/emulate.c:1110:13: runtime error: call to function do_fuse1 through pointer to incorrect function type 'bool (*)(struct riscv_internal *, const struct rv_insn *, unsigned long, unsigned int)'
/home/eleanor/code/rv32emu/src/emulate.c:415: note: do_fuse1 defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/emulate.c:1110:13
After fixing the first error with 'do_fuse1', similar errors were
observed for other functions like 'do_fuse2', 'do_fuse3', 'do_fuse4',
and 'do_jal'. The root cause was type mismatches in parameter
declarations, where 'rv_insn_t *' was used instead of the expected
'const rv_insn_t *'. Since 'do_jal' was generated by the 'RVOP'
macro in 'rv32emu_template.c', the macro was also corrected.
These changes resolve the UBSAN errors and align all function pointers
and implementations.1 parent c5607de commit 08146d9
1 file changed
+45
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
415 | 418 | | |
416 | 419 | | |
417 | 420 | | |
| |||
428 | 431 | | |
429 | 432 | | |
430 | 433 | | |
431 | | - | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
432 | 438 | | |
433 | 439 | | |
434 | 440 | | |
| |||
444 | 450 | | |
445 | 451 | | |
446 | 452 | | |
447 | | - | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
448 | 457 | | |
449 | 458 | | |
450 | 459 | | |
| |||
468 | 477 | | |
469 | 478 | | |
470 | 479 | | |
471 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
472 | 484 | | |
473 | 485 | | |
474 | 486 | | |
| |||
0 commit comments