sqlite2/sqlite-2.8.17-lemon-snprintf.patch
2019-04-10 15:14:13 -04:00

78 lines
2.9 KiB
Diff

diff -up sqlite-2.8.17/tool/lemon.c.snprintf sqlite-2.8.17/tool/lemon.c
--- sqlite-2.8.17/tool/lemon.c.snprintf 2019-04-10 14:54:06.947117428 -0400
+++ sqlite-2.8.17/tool/lemon.c 2019-04-10 14:58:20.765967958 -0400
@@ -1272,15 +1272,15 @@ void ErrorMsg(const char *filename, int
va_start(ap, format);
/* Prepare a prefix to be prepended to every output line */
if( lineno>0 ){
- sprintf(prefix,"%.*s:%d: ",PREFIXLIMIT-10,filename,lineno);
+ snprintf(prefix,sizeof prefix,"%.*s:%d: ",PREFIXLIMIT-10,filename,lineno);
}else{
- sprintf(prefix,"%.*s: ",PREFIXLIMIT-10,filename);
+ snprintf(prefix,sizeof prefix,"%.*s: ",PREFIXLIMIT-10,filename);
}
prefixsize = strlen(prefix);
availablewidth = LINEWIDTH - prefixsize;
/* Generate the error message */
- vsprintf(errmsg,format,ap);
+ vsnprintf(errmsg,sizeof errmsg,format,ap);
va_end(ap);
errmsgsize = strlen(errmsg);
/* Remove trailing '\n's from the error message. */
@@ -2675,7 +2675,7 @@ struct lemon *lemp;
while( cfp ){
char buf[20];
if( cfp->dot==cfp->rp->nrhs ){
- sprintf(buf,"(%d)",cfp->rp->index);
+ snprintf(buf,sizeof buf,"(%d)",cfp->rp->index);
fprintf(fp," %5s ",buf);
}else{
fprintf(fp," ");
@@ -2814,14 +2814,16 @@ struct lemon *lemp;
cp = strrchr(lemp->filename,'.');
if( cp ){
- sprintf(buf,"%.*s.lt",(int)(cp-lemp->filename),lemp->filename);
+ snprintf(buf,sizeof buf,"%.*s.lt",(int)(cp-lemp->filename),lemp->filename);
}else{
- sprintf(buf,"%s.lt",lemp->filename);
+ snprintf(buf,sizeof buf,"%s.lt",lemp->filename);
}
if( access(buf,004)==0 ){
tpltname = buf;
}else if( access(templatename,004)==0 ){
tpltname = templatename;
+ }else if( access("/usr/share/lemon/lempar.c",004)==0 ){
+ tpltname = "/usr/share/lemon/lempar.c";
}else{
tpltname = pathsearch(lemp->argv0,templatename,0);
}
@@ -2833,7 +2835,7 @@ struct lemon *lemp;
}
in = fopen(tpltname,"r");
if( in==0 ){
- fprintf(stderr,"Can't open the template file \"%s\".\n",templatename);
+ fprintf(stderr,"Can't open the template file \"%s\".\n",tpltname);
lemp->errorcnt++;
return 0;
}
@@ -3447,7 +3449,7 @@ int mhflag; /* Output in makeheaders
/* Generate a table containing the symbolic name of every symbol
*/
for(i=0; i<lemp->nsymbol; i++){
- sprintf(line,"\"%s\",",lemp->symbols[i]->name);
+ snprintf(line,sizeof line,"\"%s\",",lemp->symbols[i]->name);
fprintf(out," %-15s",line);
if( (i&3)==3 ){ fprintf(out,"\n"); lineno++; }
}
@@ -3562,7 +3564,7 @@ struct lemon *lemp;
in = file_open(lemp,".h","r");
if( in ){
for(i=1; i<lemp->nterminal && fgets(line,LINESIZE,in); i++){
- sprintf(pattern,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
+ snprintf(pattern,sizeof pattern,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
if( strcmp(line,pattern) ) break;
}
fclose(in);