Skip to content

Commit 35d5d96

Browse files
author
Michael Meskes
committed
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.
1 parent 8c843ff commit 35d5d96

File tree

8 files changed

+30
-18
lines changed

8 files changed

+30
-18
lines changed

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ deccopy(decimal *src, decimal *target)
178178
static char *
179179
ecpg_strndup(const char *str, size_t len)
180180
{
181-
int real_len = strlen(str);
182-
int use_len = (real_len > len) ? (int) len : real_len;
181+
size_t real_len = strlen(str);
182+
int use_len = (int) ((real_len > len) ? len : real_len);
183183

184184
char *new = malloc(use_len + 1);
185185

@@ -983,24 +983,33 @@ ldchar(char *src, int len, char *dest)
983983
int
984984
rgetmsg(int msgnum, char *s, int maxsize)
985985
{
986+
(void) msgnum; /* keep the compiler quiet */
987+
(void) s; /* keep the compiler quiet */
988+
(void) maxsize; /* keep the compiler quiet */
986989
return 0;
987990
}
988991

989992
int
990993
rtypalign(int offset, int type)
991994
{
995+
(void) offset; /* keep the compiler quiet */
996+
(void) type; /* keep the compiler quiet */
992997
return 0;
993998
}
994999

9951000
int
9961001
rtypmsize(int type, int len)
9971002
{
1003+
(void) type; /* keep the compiler quiet */
1004+
(void) len; /* keep the compiler quiet */
9981005
return 0;
9991006
}
10001007

10011008
int
10021009
rtypwidth(int sqltype, int sqllen)
10031010
{
1011+
(void) sqltype; /* keep the compiler quiet */
1012+
(void) sqllen; /* keep the compiler quiet */
10041013
return 0;
10051014
}
10061015

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
214214
char *sqlstate = PQresultErrorField(result, PG_DIAG_SQLSTATE);
215215
char *message = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
216216
struct sqlca_t *sqlca = ECPGget_sqlca();
217-
218217
int sqlcode;
219218

219+
(void) arg; /* keep the compiler quiet */
220220
if (sqlstate == NULL)
221221
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
222222

src/interfaces/ecpg/ecpglib/extern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct connection
7676
{
7777
char *name;
7878
PGconn *connection;
79-
int autocommit;
79+
bool autocommit;
8080
struct ECPGtype_information_cache *cache_head;
8181
struct prepared_statement *prep_stmts;
8282
struct connection *next;

src/interfaces/ecpg/ecpglib/memory.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static pthread_once_t auto_mem_once = PTHREAD_ONCE_INIT;
7575
static void
7676
auto_mem_destructor(void *arg)
7777
{
78+
(void) arg; /* keep the compiler quiet */
7879
ECPGfree_auto_mem();
7980
}
8081

src/interfaces/ecpg/ecpglib/prepare.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ replace_variables(char **text, int lineno)
100100
}
101101

102102
static bool
103-
prepare_common(int lineno, struct connection * con, const bool questionmarks, const char *name, const char *variable)
103+
prepare_common(int lineno, struct connection * con, const char *name, const char *variable)
104104
{
105105
struct statement *stmt;
106106
struct prepared_statement *this;
@@ -156,14 +156,15 @@ prepare_common(int lineno, struct connection * con, const bool questionmarks, co
156156
}
157157

158158
/* handle the EXEC SQL PREPARE statement */
159-
/* questionmarks is not needed but remians in there for the time being to not change the API */
159+
/* questionmarks is not needed but remains in there for the time being to not change the API */
160160
bool
161161
ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
162162
{
163163
struct connection *con;
164164
struct prepared_statement *this,
165165
*prev;
166166

167+
(void) questionmarks; /* quiet the compiler */
167168
con = ecpg_get_connection(connection_name);
168169

169170
if (!ecpg_init(con, connection_name, lineno))
@@ -174,7 +175,7 @@ ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, c
174175
if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
175176
return false;
176177

177-
return prepare_common(lineno, con, questionmarks, name, variable);
178+
return prepare_common(lineno, con, name, variable);
178179
}
179180

180181
struct prepared_statement *
@@ -304,6 +305,7 @@ ecpg_prepared(const char *name, struct connection * con)
304305
char *
305306
ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
306307
{
308+
(void)lineno; /* keep the compiler quiet */
307309
return ecpg_prepared(name, ecpg_get_connection(connection_name));
308310
}
309311

@@ -484,7 +486,7 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, cha
484486
con = ecpg_get_connection(connection_name);
485487
prep = ecpg_find_prepared_statement(stmtID, con, NULL);
486488
/* This prepared name doesn't exist on this connection. */
487-
if (!prep && !prepare_common(lineno, con, 0, stmtID, query))
489+
if (!prep && !prepare_common(lineno, con, stmtID, query))
488490
return (false);
489491

490492
*name = ecpg_strdup(stmtID, lineno);

src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
#include "extern.h"
1313

14-
int ret_value = 0,
15-
autocommit = false,
14+
int ret_value = 0;
15+
bool autocommit = false,
1616
auto_create_c = false,
1717
system_includes = false,
1818
force_indicator = true,
@@ -126,9 +126,9 @@ main(int argc, char *const argv[])
126126

127127
int fnr,
128128
c,
129-
verbose = false,
130-
header_mode = false,
131129
out_option = 0;
130+
bool verbose = false,
131+
header_mode = false;
132132
struct _include_path *ip;
133133
const char *progname;
134134
char my_exec_path[MAXPGPATH];

src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ prepared_name: name {
270270
$$ = $1;
271271
else /* not quoted => convert to lowercase */
272272
{
273-
int i;
273+
size_t i;
274274

275275
for (i = 0; i< strlen($1); i++)
276276
$1[i] = tolower((unsigned char) $1[i]);

src/interfaces/ecpg/preproc/extern.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818

1919
/* variables */
2020

21-
extern int braces_open,
22-
autocommit,
21+
extern bool autocommit,
2322
auto_create_c,
2423
system_includes,
2524
force_indicator,
2625
questionmarks,
27-
ret_value,
28-
struct_level,
29-
ecpg_internal_var,
3026
regression_mode,
3127
auto_prepare;
28+
extern int braces_open,
29+
ret_value,
30+
struct_level,
31+
ecpg_internal_var;
3232
extern char *current_function;
3333
extern char *descriptor_index;
3434
extern char *descriptor_name;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy