From 6216e84df611759f626107180f47087260e36ca9 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 18 Apr 2000 00:24:30 +0000 Subject: [PATCH] Make ECPGraise's str parameter const to suppress warnings from gcc and errors from pickier compilers. --- src/interfaces/ecpg/include/ecpglib.h | 2 +- src/interfaces/ecpg/lib/error.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h index 8b7e1ecd40..f255e4f28a 100644 --- a/src/interfaces/ecpg/include/ecpglib.h +++ b/src/interfaces/ecpg/include/ecpglib.h @@ -34,7 +34,7 @@ extern "C" const char *descriptor, const char *query); bool ECPGdeallocate_desc(int line, const char *name); bool ECPGallocate_desc(int line, const char *name); - void ECPGraise(int line, int code, char *str); + void ECPGraise(int line, int code, const char *str); bool ECPGget_desc_header(int, char *, int *); bool ECPGget_desc(int, char *, int,...); diff --git a/src/interfaces/ecpg/lib/error.c b/src/interfaces/ecpg/lib/error.c index e2da331757..369972687c 100644 --- a/src/interfaces/ecpg/lib/error.c +++ b/src/interfaces/ecpg/lib/error.c @@ -7,7 +7,7 @@ #include void -ECPGraise(int line, int code, char *str) +ECPGraise(int line, int code, const char *str) { sqlca.sqlcode = code; @@ -119,13 +119,15 @@ ECPGraise(int line, int code, char *str) break; case ECPG_PGSQL: + { + int slen = strlen(str); /* strip trailing newline */ - if (str[strlen(str) - 1] == '\n') - str[strlen(str) - 1] = '\0'; - + if (slen > 0 && str[slen - 1] == '\n') + slen--; snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), - "'%s' in line %d.", str, line); + "'%.*s' in line %d.", slen, str, line); break; + } case ECPG_TRANS: snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),