Skip to content

Commit b5c838e

Browse files
committed
Clean up ecpg's use of mmerror(): const-ify the format argument, add an
__attribute__() marker so that gcc can validate the format string against the actual arguments, get rid of overcomplicated and unsafe usage in base_yyerror().
1 parent a734979 commit b5c838e

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/interfaces/ecpg/preproc/ecpg.header

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.header,v 1.5 2009/01/23 12:43:32 petere Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.header,v 1.6 2009/06/03 20:24:51 tgl Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -56,7 +56,7 @@ struct ECPGtype ecpg_query = {ECPGt_char_variable, NULL, NULL, {NULL}, 0};
5656
* Handle parsing errors and warnings
5757
*/
5858
void
59-
mmerror(int error_code, enum errortype type, char * error, ...)
59+
mmerror(int error_code, enum errortype type, const char *error, ...)
6060
{
6161
va_list ap;
6262

src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.7 2009/04/06 08:42:53 heikki Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.8 2009/06/03 20:24:51 tgl Exp $ */
22

33
statements: /*EMPTY*/
44
| statements statement
@@ -1985,13 +1985,10 @@ ecpg_into: INTO into_list { $$ = EMPTY; }
19851985

19861986
%%
19871987

1988-
void base_yyerror(const char * error)
1988+
void base_yyerror(const char *error)
19891989
{
1990-
char buf[1024];
1991-
1992-
snprintf(buf,sizeof buf, _("%s at or near \"%s\""), error, token_start ? token_start : yytext);
1993-
buf[sizeof(buf)-1]=0;
1994-
mmerror(PARSE_ERROR, ET_ERROR, buf);
1990+
mmerror(PARSE_ERROR, ET_ERROR, "%s at or near \"%s\"",
1991+
error, token_start ? token_start : yytext);
19951992
}
19961993

19971994
void parser_init(void)

src/interfaces/ecpg/preproc/extern.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.71 2008/05/20 23:17:32 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.72 2009/06/03 20:24:51 tgl Exp $ */
22

33
#ifndef _ECPG_PREPROC_EXTERN_H
44
#define _ECPG_PREPROC_EXTERN_H
@@ -74,7 +74,9 @@ extern int base_yylex(void);
7474
extern void base_yyerror(const char *);
7575
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
7676
extern char *mm_strdup(const char *);
77-
extern void mmerror(int, enum errortype, char *,...);
77+
extern void mmerror(int, enum errortype, const char *, ...)
78+
/* This extension allows gcc to check the format string */
79+
__attribute__((format(printf, 3, 4)));
7880
extern void output_get_descr_header(char *);
7981
extern void output_get_descr(char *, char *);
8082
extern void output_set_descr_header(char *);

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