From 35d5d962e1777560baf6f5edec906a907a853c9a Mon Sep 17 00:00:00 2001
From: Michael Meskes <meskes@postgresql.org>
Date: Tue, 2 Nov 2010 18:12:01 +0100
Subject: [PATCH] Some cleanup in ecpg code:

Use bool as type for booleans instead of int.
Do not implicitely cast size_t to int.
Make the compiler stop complaining about unused variables by adding an empty statement.
---
 src/interfaces/ecpg/compatlib/informix.c | 13 +++++++++++--
 src/interfaces/ecpg/ecpglib/connect.c    |  2 +-
 src/interfaces/ecpg/ecpglib/extern.h     |  2 +-
 src/interfaces/ecpg/ecpglib/memory.c     |  1 +
 src/interfaces/ecpg/ecpglib/prepare.c    | 10 ++++++----
 src/interfaces/ecpg/preproc/ecpg.c       |  8 ++++----
 src/interfaces/ecpg/preproc/ecpg.trailer |  2 +-
 src/interfaces/ecpg/preproc/extern.h     | 10 +++++-----
 8 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c
index 641f01adf5b..af185d533b9 100644
--- a/src/interfaces/ecpg/compatlib/informix.c
+++ b/src/interfaces/ecpg/compatlib/informix.c
@@ -178,8 +178,8 @@ deccopy(decimal *src, decimal *target)
 static char *
 ecpg_strndup(const char *str, size_t len)
 {
-	int			real_len = strlen(str);
-	int			use_len = (real_len > len) ? (int) len : real_len;
+	size_t		real_len = strlen(str);
+	int		use_len = (int) ((real_len > len) ? len : real_len);
 
 	char	   *new = malloc(use_len + 1);
 
@@ -983,24 +983,33 @@ ldchar(char *src, int len, char *dest)
 int
 rgetmsg(int msgnum, char *s, int maxsize)
 {
+	(void) msgnum; /* keep the compiler quiet */
+	(void) s; /* keep the compiler quiet */
+	(void) maxsize; /* keep the compiler quiet */
 	return 0;
 }
 
 int
 rtypalign(int offset, int type)
 {
+	(void) offset; /* keep the compiler quiet */
+	(void) type; /* keep the compiler quiet */
 	return 0;
 }
 
 int
 rtypmsize(int type, int len)
 {
+	(void) type; /* keep the compiler quiet */
+	(void) len; /* keep the compiler quiet */
 	return 0;
 }
 
 int
 rtypwidth(int sqltype, int sqllen)
 {
+	(void) sqltype; /* keep the compiler quiet */
+	(void) sqllen; /* keep the compiler quiet */
 	return 0;
 }
 
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 0091b5dc98f..3bd6614e723 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -214,9 +214,9 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
 	char	   *sqlstate = PQresultErrorField(result, PG_DIAG_SQLSTATE);
 	char	   *message = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
 	struct sqlca_t *sqlca = ECPGget_sqlca();
-
 	int			sqlcode;
 
+	(void) arg; /* keep the compiler quiet */
 	if (sqlstate == NULL)
 		sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
 
diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h
index 2d9636d798b..0d55102d0da 100644
--- a/src/interfaces/ecpg/ecpglib/extern.h
+++ b/src/interfaces/ecpg/ecpglib/extern.h
@@ -76,7 +76,7 @@ struct connection
 {
 	char	   *name;
 	PGconn	   *connection;
-	int			autocommit;
+	bool		autocommit;
 	struct ECPGtype_information_cache *cache_head;
 	struct prepared_statement *prep_stmts;
 	struct connection *next;
diff --git a/src/interfaces/ecpg/ecpglib/memory.c b/src/interfaces/ecpg/ecpglib/memory.c
index 94414b5e992..542bfc0c7d5 100644
--- a/src/interfaces/ecpg/ecpglib/memory.c
+++ b/src/interfaces/ecpg/ecpglib/memory.c
@@ -75,6 +75,7 @@ static pthread_once_t auto_mem_once = PTHREAD_ONCE_INIT;
 static void
 auto_mem_destructor(void *arg)
 {
+	(void) arg; /* keep the compiler quiet */
 	ECPGfree_auto_mem();
 }
 
diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c
index c2725a231ab..90288d343bf 100644
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -100,7 +100,7 @@ replace_variables(char **text, int lineno)
 }
 
 static bool
-prepare_common(int lineno, struct connection * con, const bool questionmarks, const char *name, const char *variable)
+prepare_common(int lineno, struct connection * con, const char *name, const char *variable)
 {
 	struct statement *stmt;
 	struct prepared_statement *this;
@@ -156,7 +156,7 @@ prepare_common(int lineno, struct connection * con, const bool questionmarks, co
 }
 
 /* handle the EXEC SQL PREPARE statement */
-/* questionmarks is not needed but remians in there for the time being to not change the API */
+/* questionmarks is not needed but remains in there for the time being to not change the API */
 bool
 ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
 {
@@ -164,6 +164,7 @@ ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, c
 	struct prepared_statement *this,
 			   *prev;
 
+	(void) questionmarks; /* quiet the compiler */	
 	con = ecpg_get_connection(connection_name);
 
 	if (!ecpg_init(con, connection_name, lineno))
@@ -174,7 +175,7 @@ ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, c
 	if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
 		return false;
 
-	return prepare_common(lineno, con, questionmarks, name, variable);
+	return prepare_common(lineno, con, name, variable);
 }
 
 struct prepared_statement *
@@ -304,6 +305,7 @@ ecpg_prepared(const char *name, struct connection * con)
 char *
 ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
 {
+	(void)lineno; /* keep the compiler quiet */
 	return ecpg_prepared(name, ecpg_get_connection(connection_name));
 }
 
@@ -484,7 +486,7 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, cha
 		con = ecpg_get_connection(connection_name);
 		prep = ecpg_find_prepared_statement(stmtID, con, NULL);
 		/* This prepared name doesn't exist on this connection. */
-		if (!prep && !prepare_common(lineno, con, 0, stmtID, query))
+		if (!prep && !prepare_common(lineno, con, stmtID, query))
 			return (false);
 
 		*name = ecpg_strdup(stmtID, lineno);
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index df1ddfd818f..917200abd0b 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -11,8 +11,8 @@
 
 #include "extern.h"
 
-int			ret_value = 0,
-			autocommit = false,
+int			ret_value = 0;
+bool			autocommit = false,
 			auto_create_c = false,
 			system_includes = false,
 			force_indicator = true,
@@ -126,9 +126,9 @@ main(int argc, char *const argv[])
 
 	int			fnr,
 				c,
-				verbose = false,
-				header_mode = false,
 				out_option = 0;
+	bool			verbose = false,
+				header_mode = false;
 	struct _include_path *ip;
 	const char *progname;
 	char		my_exec_path[MAXPGPATH];
diff --git a/src/interfaces/ecpg/preproc/ecpg.trailer b/src/interfaces/ecpg/preproc/ecpg.trailer
index 2ef6c3618e8..2eaef25c534 100644
--- a/src/interfaces/ecpg/preproc/ecpg.trailer
+++ b/src/interfaces/ecpg/preproc/ecpg.trailer
@@ -270,7 +270,7 @@ prepared_name: name             {
                                                 $$ = $1;
                                         else /* not quoted => convert to lowercase */
                                         {
-                                                int i;
+                                                size_t i;
 
                                                 for (i = 0; i< strlen($1); i++)
                                                         $1[i] = tolower((unsigned char) $1[i]);
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index 202baacc3d8..e9d5b7e83c0 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -18,17 +18,17 @@
 
 /* variables */
 
-extern int	braces_open,
-			autocommit,
+extern bool		autocommit,
 			auto_create_c,
 			system_includes,
 			force_indicator,
 			questionmarks,
-			ret_value,
-			struct_level,
-			ecpg_internal_var,
 			regression_mode,
 			auto_prepare;
+extern int		braces_open,
+			ret_value,
+			struct_level,
+			ecpg_internal_var;
 extern char *current_function;
 extern char *descriptor_index;
 extern char *descriptor_name;
-- 
GitLab