Commit 35d5d962 authored by Michael Meskes's avatar Michael Meskes

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.
parent 8c843fff
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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();
}
......
......@@ -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);
......
......@@ -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];
......
......@@ -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]);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment