Commit 316ca0f
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 cf50400 commit 316ca0f
1 file changed
+45
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
377 | | - | |
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 | | - | |
| 377 | + | |
| 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 | 406 | | |
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
413 | 416 | | |
414 | 417 | | |
415 | 418 | | |
| |||
426 | 429 | | |
427 | 430 | | |
428 | 431 | | |
429 | | - | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
430 | 436 | | |
431 | 437 | | |
432 | 438 | | |
| |||
442 | 448 | | |
443 | 449 | | |
444 | 450 | | |
445 | | - | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
446 | 455 | | |
447 | 456 | | |
448 | 457 | | |
| |||
466 | 475 | | |
467 | 476 | | |
468 | 477 | | |
469 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
470 | 482 | | |
471 | 483 | | |
472 | 484 | | |
| |||
0 commit comments