From 580170d9745a0883b69c8d63d21553d9ad874698 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Wed, 2 Dec 2020 12:27:42 +0000 Subject: [PATCH] Fix segfault under mingw32 due to dynamic cast of invalid pointer value. sync_cb::run_run() attempts to cast the obj field of the callback data to a __vpiSysTaskCall pointer. But a sync_cb object is only used for simulation time callbacks, where the obj field is (mostly) not used, so I can't see that would ever succeed. As the obj field is not required to be set by the user, the dynamic cast results in undefined behaviour, so mingw32 is not to blame. This code was introduced by Johann Klammer in commit c79df7c44, but the user klammerj and all trace of that pull request have vanished from GitHub, and there is no associated regression test, so I can't establish the rationale for it. (cherry picked from commit 8da8261fc3df4aebe4fcf0e64522b5335a752826) --- vvp/vpi_callback.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/vvp/vpi_callback.cc b/vvp/vpi_callback.cc index a3637b47e..d4f306a18 100644 --- a/vvp/vpi_callback.cc +++ b/vvp/vpi_callback.cc @@ -320,9 +320,7 @@ void sync_cb::run_run() if (cur->cb_data.cb_rtn != 0) { assert(vpi_mode_flag == VPI_MODE_NONE); vpi_mode_flag = sync_flag? VPI_MODE_ROSYNC : VPI_MODE_RWSYNC; - vpip_cur_task = dynamic_cast<__vpiSysTaskCall*>(cur->cb_data.obj); (cur->cb_data.cb_rtn)(&cur->cb_data); - vpip_cur_task = 0; vpi_mode_flag = VPI_MODE_NONE; }