Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6216e84

Browse files
committed
Make ECPGraise's str parameter const to suppress warnings from gcc
and errors from pickier compilers.
1 parent 3b192c2 commit 6216e84

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/interfaces/ecpg/include/ecpglib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern "C"
3434
const char *descriptor, const char *query);
3535
bool ECPGdeallocate_desc(int line, const char *name);
3636
bool ECPGallocate_desc(int line, const char *name);
37-
void ECPGraise(int line, int code, char *str);
37+
void ECPGraise(int line, int code, const char *str);
3838
bool ECPGget_desc_header(int, char *, int *);
3939
bool ECPGget_desc(int, char *, int,...);
4040

src/interfaces/ecpg/lib/error.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <sqlca.h>
88

99
void
10-
ECPGraise(int line, int code, char *str)
10+
ECPGraise(int line, int code, const char *str)
1111
{
1212
sqlca.sqlcode = code;
1313

@@ -119,13 +119,15 @@ ECPGraise(int line, int code, char *str)
119119
break;
120120

121121
case ECPG_PGSQL:
122+
{
123+
int slen = strlen(str);
122124
/* strip trailing newline */
123-
if (str[strlen(str) - 1] == '\n')
124-
str[strlen(str) - 1] = '\0';
125-
125+
if (slen > 0 && str[slen - 1] == '\n')
126+
slen--;
126127
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
127-
"'%s' in line %d.", str, line);
128+
"'%.*s' in line %d.", slen, str, line);
128129
break;
130+
}
129131

130132
case ECPG_TRANS:
131133
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),

0 commit comments

Comments
 (0)