From 5a5bd4a1885468aaa78b76a44f3e7145d2366185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net> Date: Mon, 13 Jan 2025 12:37:30 -0500 Subject: [PATCH] More fixups... Some Coverity issues, some deadlocks, some crashes... Just misc stuff. --- src/conio/bitmap_con.c | 14 +++++++++++--- src/conio/sdl_con.c | 12 ++++++------ src/xpdev/Common.gmake | 5 +++++ src/xpdev/genwrap.c | 2 ++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/conio/bitmap_con.c b/src/conio/bitmap_con.c index a614f23d3f..8a217c3e96 100644 --- a/src/conio/bitmap_con.c +++ b/src/conio/bitmap_con.c @@ -814,15 +814,16 @@ bitmap_draw_vmem(int sx, int sy, int ex, int ey, struct vmem_cell *fill) size_t xoffset = (sx-1) * vstat.charwidth; size_t yoffset = (sy-1) * vstat.charheight; + bs.expand = vstat.flags & VIDMODES_FLAG_EXPAND; + bs.font_data_width = vstat.charwidth - (bs.expand ? 1 : 0); + + pthread_mutex_lock(&screenlock); assert(xoffset + vstat.charwidth <= screena.screenwidth); assert(xoffset + vstat.charwidth <= screenb.screenwidth); assert(yoffset + vstat.charheight <= screena.screenheight); assert(yoffset + vstat.charheight <= screenb.screenheight); bs.maxpix = screena.screenwidth * screena.screenheight; - bs.expand = vstat.flags & VIDMODES_FLAG_EXPAND; - bs.font_data_width = vstat.charwidth - (bs.expand ? 1 : 0); - pthread_mutex_lock(&screenlock); bs.pixeloffset = pixel_offset(&screena, xoffset, yoffset); bs.cheat_colour = fill[0].bg; size_t rsz = screena.screenwidth - vstat.charwidth * vwidth; @@ -971,6 +972,13 @@ static void blinker_thread(void *data) lfc = force_cursor; force_cursor = 0; blink = vstat.blink; + pthread_mutex_lock(&screenlock); + if (screena.rect == NULL) { + pthread_mutex_unlock(&screenlock); + do_rwlock_unlock(&vstatlock); + continue; + } + pthread_mutex_unlock(&screenlock); do_rwlock_unlock(&vstatlock); if (check_redraw()) { diff --git a/src/conio/sdl_con.c b/src/conio/sdl_con.c index a44d7c9a2b..50e1de544b 100644 --- a/src/conio/sdl_con.c +++ b/src/conio/sdl_con.c @@ -756,8 +756,8 @@ static void sdl_add_key(unsigned int keyval, struct video_stats *vs) if(keyval <= 0xffff) { pthread_mutex_lock(&sdl_keylock); if(sdl_keynext+1==sdl_key) { - beep(); pthread_mutex_unlock(&sdl_keylock); + beep(); return; } if((sdl_keynext+2==sdl_key) && keyval > 0xff) { @@ -990,7 +990,7 @@ void sdl_video_event_thread(void *data) } else { if (bios_key >= 26 || - (bios_key == 429496729 && ((ev.key.keysym.sym > SDLK_KP_5) || (ev.key.keysym.sym == SDLK_KP_0)))) { + (bios_key == 25 && ((ev.key.keysym.sym > SDLK_KP_5) || (ev.key.keysym.sym == SDLK_KP_0)))) { terminate_bios = true; } } @@ -1146,8 +1146,10 @@ void sdl_video_event_thread(void *data) case SDL_WINDOWEVENT_SIZE_CHANGED: // SDL2: User resized window case SDL_WINDOWEVENT_RESIZED: + pthread_mutex_lock(&win_mutex); fullscreen = !!(sdl.GetWindowFlags(win) & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP)); sdl.SetWindowResizable(win, fullscreen ? SDL_FALSE : SDL_TRUE); + pthread_mutex_unlock(&win_mutex); cio_api.mode=fullscreen?CIOLIB_MODE_SDL_FULLSCREEN:CIOLIB_MODE_SDL; pthread_mutex_lock(&sdl_mode_mutex); if (sdl_mode) { @@ -1326,17 +1328,17 @@ void sdl_video_event_thread(void *data) case SDL_USEREVENT_INIT: if(!sdl_init_good) { if(sdl.WasInit(SDL_INIT_VIDEO)==SDL_INIT_VIDEO) { - pthread_mutex_lock(&win_mutex); _beginthread(sdl_mouse_thread, 0, NULL); sdl_init_good=1; - pthread_mutex_unlock(&win_mutex); } } sdl_ufunc_retval=0; sem_post(&sdl_ufunc_ret); break; case SDL_USEREVENT_GETWINPOS: + pthread_mutex_lock(&win_mutex); sdl.GetWindowPosition(win, ev.user.data1, ev.user.data2); + pthread_mutex_unlock(&win_mutex); sem_post(&sdl_ufunc_ret); break; case SDL_USEREVENT_MOUSEPOINTER: @@ -1380,8 +1382,6 @@ void sdl_video_event_thread(void *data) break; } } - sdl.QuitSubSystem(SDL_INIT_VIDEO); - return; } static int diff --git a/src/xpdev/Common.gmake b/src/xpdev/Common.gmake index 1bf8c62a71..283b14578e 100644 --- a/src/xpdev/Common.gmake +++ b/src/xpdev/Common.gmake @@ -218,6 +218,11 @@ ifndef WITHOUT_ALSA_SOUND ifeq ($(shell if [ -f /usr/include/alsa/asoundlib.h ] ; then echo YES ; fi),YES) XPDEV-MT_CFLAGS += -DUSE_ALSA_SOUND XPDEV-MT_LIBS += -ldl + else + ifeq ($(shell if [ -f /usr/local/include/alsa/asoundlib.h ] ; then echo YES ; fi),YES) + XPDEV-MT_CFLAGS += -DUSE_ALSA_SOUND + XPDEV-MT_LIBS += -ldl + endif endif endif diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c index 0937e62c35..af4b60eb12 100644 --- a/src/xpdev/genwrap.c +++ b/src/xpdev/genwrap.c @@ -1147,8 +1147,10 @@ int64_t xp_fast_timer64(void) } cid = CLOCK_MONOTONIC_RAW; #endif +#ifdef CLOCK_MONOTONIC if (cid == CLOCK_REALTIME) cid = CLOCK_MONOTONIC; +#endif if (clock_gettime(cid, &ts) == 0) ret = ts.tv_sec; -- GitLab