Make ECPGraise's str parameter const to suppress warnings from gcc
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Apr 2000 00:24:30 +0000 (00:24 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Apr 2000 00:24:30 +0000 (00:24 +0000)
and errors from pickier compilers.

src/interfaces/ecpg/include/ecpglib.h
src/interfaces/ecpg/lib/error.c

index 8b7e1ecd40362bf584c708e0e9fa520260079f75..f255e4f28a057ee03d3db20ba8869cdfb19241e9 100644 (file)
@@ -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,...);
 
index e2da331757afc417aa1a222484c3cd3b099d1dc9..369972687cd7b51296d1c41dd4a6533383313c9b 100644 (file)
@@ -7,7 +7,7 @@
 #include <sqlca.h>
 
 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),