From 5727d70622573608c8a45eba8f183f136c396efe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net>
Date: Thu, 15 Feb 2024 18:02:28 -0500
Subject: [PATCH] Move fiddling with rip.x_max and rip.y_max out of the vstat
 mutex.

Apparently, fiddling with them in there "strongly implies" to Coverity
that vstatlock needs to be held to access them, and it's good form
to have the lock held for the least span possible.
---
 src/syncterm/ripper.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/syncterm/ripper.c b/src/syncterm/ripper.c
index a2807b808c..ffc5eb7122 100644
--- a/src/syncterm/ripper.c
+++ b/src/syncterm/ripper.c
@@ -8090,9 +8090,10 @@ rv_termset(const char * const var, const void * const data)
 							rip.y_dim = 350;
 							pthread_mutex_lock(&vstatlock);
 							rip.x_max = vstat.scrnwidth;
+							rip.y_max = vstat.scrnheight;
+							pthread_mutex_unlock(&vstatlock);
 							if (rip.x_max > rip.x_dim)
 								rip.x_max = rip.x_dim;
-							rip.y_max = vstat.scrnheight;
 							if (rip.y_max > rip.y_dim)
 								rip.y_max = rip.y_dim;
 
@@ -8105,7 +8106,6 @@ rv_termset(const char * const var, const void * const data)
 							FREE_AND_NULL(rip.ymap);
 							FREE_AND_NULL(rip.xunmap);
 							FREE_AND_NULL(rip.yunmap);
-							pthread_mutex_unlock(&vstatlock);
 							return NULL;
 					}
 					break;
@@ -11708,9 +11708,10 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
 							rip.y_dim = y1;
 							pthread_mutex_lock(&vstatlock);
 							rip.x_max = vstat.scrnwidth;
+							rip.y_max = vstat.scrnheight;
+							pthread_mutex_unlock(&vstatlock);
 							if (rip.x_max > rip.x_dim)
 								rip.x_max = rip.x_dim;
-							rip.y_max = vstat.scrnheight;
 							if (rip.y_max > rip.y_dim)
 								rip.y_max = rip.y_dim;
 
@@ -11723,7 +11724,6 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
 							FREE_AND_NULL(rip.ymap);
 							FREE_AND_NULL(rip.xunmap);
 							FREE_AND_NULL(rip.yunmap);
-							pthread_mutex_unlock(&vstatlock);
 							break;
 						case 'g': // RIP_GOTOXY !|g <x> <y>
                                                         /* This command sets the position of the text cursor in the TTY
@@ -16149,13 +16149,13 @@ init_rip(struct bbslist *bbs)
 	if (cio_api.options & CONIO_OPT_SET_PIXEL) {
 		pthread_mutex_lock(&vstatlock);
 		rip.x_max = vstat.scrnwidth;
+		rip.y_max = vstat.scrnheight;
+		pthread_mutex_unlock(&vstatlock);
 		if (rip.x_max > rip.x_dim)
 			rip.x_max = rip.x_dim;
 		rip.y_dim = 350;
-		rip.y_max = vstat.scrnheight;
 		if (rip.y_max > rip.y_dim)
 			rip.y_max = rip.y_dim;
-		pthread_mutex_unlock(&vstatlock);
 	}
 	rip.viewport.ex = rip.x_dim - 1;
 	rip.viewport.ey = rip.y_dim - 1;
-- 
GitLab