Переглянути джерело

Fix PSV Studio warnings for Linux build (#597)

bel2125 6 роки тому
батько
коміт
855b770053
2 змінених файлів з 16 додано та 13 видалено
  1. 11 12
      src/civetweb.c
  2. 5 1
      src/main.c

+ 11 - 12
src/civetweb.c

@@ -4098,7 +4098,7 @@ reparse:
 	end = (int)val->len - 1;
 	while (end >= 0 && ((val->ptr[end] == ' ') || (val->ptr[end] == '\t')))
 		end--;
-	val->len = (size_t)(end + 1);
+	val->len = (size_t)(end) + (size_t)(1);
 
 	if (val->len == 0) {
 		/* Ignore any empty entries. */
@@ -10972,6 +10972,7 @@ abort_process(void *data)
 }
 
 
+/* Local (static) function assumes all arguments are valid. */
 static void
 handle_cgi_request(struct mg_connection *conn, const char *prog)
 {
@@ -10996,10 +10997,6 @@ handle_cgi_request(struct mg_connection *conn, const char *prog)
 	}
 #endif
 
-	if (conn == NULL) {
-		return;
-	}
-
 	buf = NULL;
 	buflen = conn->phys_ctx->max_request_size;
 	i = prepare_cgi_environment(conn, prog, &blk);
@@ -12004,8 +12001,9 @@ static int
 print_dav_dir_entry(struct de *de, void *data)
 {
 	struct mg_connection *conn = (struct mg_connection *)data;
-	if (!de || !conn || !print_props(conn, conn->request_info.local_uri,
-	                                 de->file_name, &de->file)) {
+	if (!de || !conn
+	    || !print_props(
+	           conn, conn->request_info.local_uri, de->file_name, &de->file)) {
 		return -1;
 	}
 	return 0;
@@ -15160,8 +15158,9 @@ sslize(struct mg_connection *conn,
 					struct mg_pollfd pfd;
 					pfd.fd = conn->client.sock;
 					pfd.events = ((err == SSL_ERROR_WANT_CONNECT)
-					              || (err == SSL_ERROR_WANT_WRITE)) ? POLLOUT
-					                                                : POLLIN;
+					              || (err == SSL_ERROR_WANT_WRITE))
+					                 ? POLLOUT
+					                 : POLLIN;
 					mg_poll(&pfd, 1, 50, stop_server);
 				}
 
@@ -17845,8 +17844,7 @@ worker_thread_run(struct mg_connection *conn)
 	/* Connection structure has been pre-allocated */
 	thread_index = (int)(conn - ctx->worker_connections);
 	if ((thread_index < 0)
-	    || ((unsigned)thread_index
-	        >= (unsigned)ctx->cfg_worker_threads)) {
+	    || ((unsigned)thread_index >= (unsigned)ctx->cfg_worker_threads)) {
 		mg_cry_internal(fc(ctx),
 		                "Internal error: Invalid worker index %i",
 		                thread_index);
@@ -18724,7 +18722,8 @@ mg_start(const struct mg_callbacks *callbacks,
 		ctx->worker_connections[i].phys_ctx = ctx;
 		if (mg_start_thread_with_id(worker_thread,
 		                            &ctx->worker_connections[i],
-		                            &ctx->worker_threadids[i]) != 0) {
+		                            &ctx->worker_threadids[i])
+		    != 0) {
 
 			/* thread was not created */
 			if (i > 0) {

+ 5 - 1
src/main.c

@@ -167,7 +167,11 @@ struct tuser_data {
 };
 
 
-static int g_exit_flag = 0;         /* Main loop should exit */
+/* Exit flag for the main loop (read and writen by different threads, thus
+ * volatile). */
+volatile int g_exit_flag = 0; /* 0 = continue running main loop */
+
+
 static char g_server_base_name[40]; /* Set by init_server_name() */
 
 static const char *g_server_name; /* Default from init_server_name,