From 061a5b53fc2d3fa673be629dc03a0ba4710bab83 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 25 Oct 2022 21:23:22 +0300 Subject: [PATCH 18/18] Fix clang analyzer warnings from luasql code See osdn #45872 Signed-off-by: Marko Lindqvist --- dependencies/luasql/Makefile.am | 3 +- dependencies/luasql/Version.txt | 3 + dependencies/luasql/clang_analyzer.patch | 102 +++++++++++++++++++++++ dependencies/luasql/src/ls_mysql.c | 9 +- dependencies/luasql/src/ls_postgres.c | 9 +- dependencies/luasql/src/ls_sqlite3.c | 9 +- 6 files changed, 125 insertions(+), 10 deletions(-) create mode 100644 dependencies/luasql/clang_analyzer.patch diff --git a/dependencies/luasql/Makefile.am b/dependencies/luasql/Makefile.am index b919e47d08..58482130a3 100644 --- a/dependencies/luasql/Makefile.am +++ b/dependencies/luasql/Makefile.am @@ -4,4 +4,5 @@ SUBDIRS = src EXTRA_DIST = \ README \ - Version.txt + Version.txt \ + clang_analyzer.patch diff --git a/dependencies/luasql/Version.txt b/dependencies/luasql/Version.txt index d9b81fb7f3..6fe44eaa4b 100644 --- a/dependencies/luasql/Version.txt +++ b/dependencies/luasql/Version.txt @@ -2,6 +2,9 @@ Sources here are fron luasql git tag v2.4.0 (https://github.com/keplerproject/luasql/tree/v2.4.0) Some modifications have been done to them, but as of 08-Oct-22 all our modifications have been accepted to the upstream. +25-Oct-22: Local patch for fixing clang analyzer warnings has + been applied. It's present also as a patch file + clang_analyzer.patch Only the files needed by freeciv are included here, not entire luasql source directory hierarchy. diff --git a/dependencies/luasql/clang_analyzer.patch b/dependencies/luasql/clang_analyzer.patch new file mode 100644 index 0000000000..7c6d1d2049 --- /dev/null +++ b/dependencies/luasql/clang_analyzer.patch @@ -0,0 +1,102 @@ +diff --git a/dependencies/luasql/src/ls_mysql.c b/dependencies/luasql/src/ls_mysql.c +index 36a99ecbe8..40768308d3 100644 +--- a/dependencies/luasql/src/ls_mysql.c ++++ b/dependencies/luasql/src/ls_mysql.c +@@ -87,7 +87,8 @@ LUASQL_API int luaopen_luasql_mysql (lua_State *L); + static env_data *getenvironment (lua_State *L) { + env_data *env = (env_data *)luaL_checkudata (L, 1, LUASQL_ENVIRONMENT_MYSQL); + luaL_argcheck (L, env != NULL, 1, "environment expected"); +- luaL_argcheck (L, !env->closed, 1, "environment is closed"); ++ if (env != NULL) ++ luaL_argcheck (L, !env->closed, 1, "environment is closed"); + return env; + } + +@@ -98,7 +99,8 @@ static env_data *getenvironment (lua_State *L) { + static conn_data *getconnection (lua_State *L) { + conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUASQL_CONNECTION_MYSQL); + luaL_argcheck (L, conn != NULL, 1, "connection expected"); +- luaL_argcheck (L, !conn->closed, 1, "connection is closed"); ++ if (conn != NULL) ++ luaL_argcheck (L, !conn->closed, 1, "connection is closed"); + return conn; + } + +@@ -109,7 +111,8 @@ static conn_data *getconnection (lua_State *L) { + static cur_data *getcursor (lua_State *L) { + cur_data *cur = (cur_data *)luaL_checkudata (L, 1, LUASQL_CURSOR_MYSQL); + luaL_argcheck (L, cur != NULL, 1, "cursor expected"); +- luaL_argcheck (L, !cur->closed, 1, "cursor is closed"); ++ if (cur != NULL) ++ luaL_argcheck (L, !cur->closed, 1, "cursor is closed"); + return cur; + } + +diff --git a/dependencies/luasql/src/ls_postgres.c b/dependencies/luasql/src/ls_postgres.c +index 62d928df28..d87e3c8360 100644 +--- a/dependencies/luasql/src/ls_postgres.c ++++ b/dependencies/luasql/src/ls_postgres.c +@@ -59,7 +59,8 @@ LUASQL_API int luaopen_luasql_postgres(lua_State *L); + static env_data *getenvironment (lua_State *L) { + env_data *env = (env_data *)luaL_checkudata (L, 1, LUASQL_ENVIRONMENT_PG); + luaL_argcheck (L, env != NULL, 1, LUASQL_PREFIX"environment expected"); +- luaL_argcheck (L, !env->closed, 1, LUASQL_PREFIX"environment is closed"); ++ if (env != NULL) ++ luaL_argcheck (L, !env->closed, 1, LUASQL_PREFIX"environment is closed"); + return env; + } + +@@ -70,7 +71,8 @@ static env_data *getenvironment (lua_State *L) { + static conn_data *getconnection (lua_State *L) { + conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUASQL_CONNECTION_PG); + luaL_argcheck (L, conn != NULL, 1, LUASQL_PREFIX"connection expected"); +- luaL_argcheck (L, !conn->closed, 1, LUASQL_PREFIX"connection is closed"); ++ if (conn != NULL) ++ luaL_argcheck (L, !conn->closed, 1, LUASQL_PREFIX"connection is closed"); + return conn; + } + +@@ -81,7 +83,8 @@ static conn_data *getconnection (lua_State *L) { + static cur_data *getcursor (lua_State *L) { + cur_data *cur = (cur_data *)luaL_checkudata (L, 1, LUASQL_CURSOR_PG); + luaL_argcheck (L, cur != NULL, 1, LUASQL_PREFIX"cursor expected"); +- luaL_argcheck (L, !cur->closed, 1, LUASQL_PREFIX"cursor is closed"); ++ if (cur != NULL) ++ luaL_argcheck (L, !cur->closed, 1, LUASQL_PREFIX"cursor is closed"); + return cur; + } + +diff --git a/dependencies/luasql/src/ls_sqlite3.c b/dependencies/luasql/src/ls_sqlite3.c +index 33672ca2b6..6b083c1ad3 100644 +--- a/dependencies/luasql/src/ls_sqlite3.c ++++ b/dependencies/luasql/src/ls_sqlite3.c +@@ -58,7 +58,8 @@ LUASQL_API int luaopen_luasql_sqlite3(lua_State *L); + static env_data *getenvironment(lua_State *L) { + env_data *env = (env_data *)luaL_checkudata(L, 1, LUASQL_ENVIRONMENT_SQLITE); + luaL_argcheck(L, env != NULL, 1, LUASQL_PREFIX"environment expected"); +- luaL_argcheck(L, !env->closed, 1, LUASQL_PREFIX"environment is closed"); ++ if (env != NULL) ++ luaL_argcheck(L, !env->closed, 1, LUASQL_PREFIX"environment is closed"); + return env; + } + +@@ -69,7 +70,8 @@ static env_data *getenvironment(lua_State *L) { + static conn_data *getconnection(lua_State *L) { + conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUASQL_CONNECTION_SQLITE); + luaL_argcheck(L, conn != NULL, 1, LUASQL_PREFIX"connection expected"); +- luaL_argcheck(L, !conn->closed, 1, LUASQL_PREFIX"connection is closed"); ++ if (conn != NULL) ++ luaL_argcheck(L, !conn->closed, 1, LUASQL_PREFIX"connection is closed"); + return conn; + } + +@@ -80,7 +82,8 @@ static conn_data *getconnection(lua_State *L) { + static cur_data *getcursor(lua_State *L) { + cur_data *cur = (cur_data *)luaL_checkudata (L, 1, LUASQL_CURSOR_SQLITE); + luaL_argcheck(L, cur != NULL, 1, LUASQL_PREFIX"cursor expected"); +- luaL_argcheck(L, !cur->closed, 1, LUASQL_PREFIX"cursor is closed"); ++ if (cur != NULL) ++ luaL_argcheck(L, !cur->closed, 1, LUASQL_PREFIX"cursor is closed"); + return cur; + } + diff --git a/dependencies/luasql/src/ls_mysql.c b/dependencies/luasql/src/ls_mysql.c index 36a99ecbe8..40768308d3 100644 --- a/dependencies/luasql/src/ls_mysql.c +++ b/dependencies/luasql/src/ls_mysql.c @@ -87,7 +87,8 @@ LUASQL_API int luaopen_luasql_mysql (lua_State *L); static env_data *getenvironment (lua_State *L) { env_data *env = (env_data *)luaL_checkudata (L, 1, LUASQL_ENVIRONMENT_MYSQL); luaL_argcheck (L, env != NULL, 1, "environment expected"); - luaL_argcheck (L, !env->closed, 1, "environment is closed"); + if (env != NULL) + luaL_argcheck (L, !env->closed, 1, "environment is closed"); return env; } @@ -98,7 +99,8 @@ static env_data *getenvironment (lua_State *L) { static conn_data *getconnection (lua_State *L) { conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUASQL_CONNECTION_MYSQL); luaL_argcheck (L, conn != NULL, 1, "connection expected"); - luaL_argcheck (L, !conn->closed, 1, "connection is closed"); + if (conn != NULL) + luaL_argcheck (L, !conn->closed, 1, "connection is closed"); return conn; } @@ -109,7 +111,8 @@ static conn_data *getconnection (lua_State *L) { static cur_data *getcursor (lua_State *L) { cur_data *cur = (cur_data *)luaL_checkudata (L, 1, LUASQL_CURSOR_MYSQL); luaL_argcheck (L, cur != NULL, 1, "cursor expected"); - luaL_argcheck (L, !cur->closed, 1, "cursor is closed"); + if (cur != NULL) + luaL_argcheck (L, !cur->closed, 1, "cursor is closed"); return cur; } diff --git a/dependencies/luasql/src/ls_postgres.c b/dependencies/luasql/src/ls_postgres.c index 62d928df28..d87e3c8360 100644 --- a/dependencies/luasql/src/ls_postgres.c +++ b/dependencies/luasql/src/ls_postgres.c @@ -59,7 +59,8 @@ LUASQL_API int luaopen_luasql_postgres(lua_State *L); static env_data *getenvironment (lua_State *L) { env_data *env = (env_data *)luaL_checkudata (L, 1, LUASQL_ENVIRONMENT_PG); luaL_argcheck (L, env != NULL, 1, LUASQL_PREFIX"environment expected"); - luaL_argcheck (L, !env->closed, 1, LUASQL_PREFIX"environment is closed"); + if (env != NULL) + luaL_argcheck (L, !env->closed, 1, LUASQL_PREFIX"environment is closed"); return env; } @@ -70,7 +71,8 @@ static env_data *getenvironment (lua_State *L) { static conn_data *getconnection (lua_State *L) { conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUASQL_CONNECTION_PG); luaL_argcheck (L, conn != NULL, 1, LUASQL_PREFIX"connection expected"); - luaL_argcheck (L, !conn->closed, 1, LUASQL_PREFIX"connection is closed"); + if (conn != NULL) + luaL_argcheck (L, !conn->closed, 1, LUASQL_PREFIX"connection is closed"); return conn; } @@ -81,7 +83,8 @@ static conn_data *getconnection (lua_State *L) { static cur_data *getcursor (lua_State *L) { cur_data *cur = (cur_data *)luaL_checkudata (L, 1, LUASQL_CURSOR_PG); luaL_argcheck (L, cur != NULL, 1, LUASQL_PREFIX"cursor expected"); - luaL_argcheck (L, !cur->closed, 1, LUASQL_PREFIX"cursor is closed"); + if (cur != NULL) + luaL_argcheck (L, !cur->closed, 1, LUASQL_PREFIX"cursor is closed"); return cur; } diff --git a/dependencies/luasql/src/ls_sqlite3.c b/dependencies/luasql/src/ls_sqlite3.c index 33672ca2b6..6b083c1ad3 100644 --- a/dependencies/luasql/src/ls_sqlite3.c +++ b/dependencies/luasql/src/ls_sqlite3.c @@ -58,7 +58,8 @@ LUASQL_API int luaopen_luasql_sqlite3(lua_State *L); static env_data *getenvironment(lua_State *L) { env_data *env = (env_data *)luaL_checkudata(L, 1, LUASQL_ENVIRONMENT_SQLITE); luaL_argcheck(L, env != NULL, 1, LUASQL_PREFIX"environment expected"); - luaL_argcheck(L, !env->closed, 1, LUASQL_PREFIX"environment is closed"); + if (env != NULL) + luaL_argcheck(L, !env->closed, 1, LUASQL_PREFIX"environment is closed"); return env; } @@ -69,7 +70,8 @@ static env_data *getenvironment(lua_State *L) { static conn_data *getconnection(lua_State *L) { conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUASQL_CONNECTION_SQLITE); luaL_argcheck(L, conn != NULL, 1, LUASQL_PREFIX"connection expected"); - luaL_argcheck(L, !conn->closed, 1, LUASQL_PREFIX"connection is closed"); + if (conn != NULL) + luaL_argcheck(L, !conn->closed, 1, LUASQL_PREFIX"connection is closed"); return conn; } @@ -80,7 +82,8 @@ static conn_data *getconnection(lua_State *L) { static cur_data *getcursor(lua_State *L) { cur_data *cur = (cur_data *)luaL_checkudata (L, 1, LUASQL_CURSOR_SQLITE); luaL_argcheck(L, cur != NULL, 1, LUASQL_PREFIX"cursor expected"); - luaL_argcheck(L, !cur->closed, 1, LUASQL_PREFIX"cursor is closed"); + if (cur != NULL) + luaL_argcheck(L, !cur->closed, 1, LUASQL_PREFIX"cursor is closed"); return cur; } -- 2.35.1