From bb3f8c8c82cc5131001cf49851d4ff3f4a95a050 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 6 Mar 2021 20:03:08 +0700 Subject: [PATCH 1/3] Do not modify `errstart` inside function `error()`, use a local variable instead --- source/compiler/sc5.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/compiler/sc5.c b/source/compiler/sc5.c index 3302cfa..1e7cb64 100644 --- a/source/compiler/sc5.c +++ b/source/compiler/sc5.c @@ -246,7 +246,7 @@ static short lastfile; char *msg,*pre; va_list argptr; char string[128]; - int notice; + int notice,start; /* split the error field between the real error/warning number and an optional * "notice" number @@ -303,15 +303,15 @@ static short lastfile; } /* if */ assert(errstart<=fline); + start=errstart; if (errline>0) - errstart=errline; + start=errline; else errline=fline; - assert(errstart<=errline); + assert(start<=errline); va_start(argptr,number); if (errfname[0]=='\0') { - int start=(errstart==errline) ? -1 : errstart; - if (pc_error((int)number,msg,inpfname,start,errline,argptr)) { + if (pc_error((int)number,msg,inpfname,((start==errline) ? -1 : start),errline,argptr)) { if (outf!=NULL) { pc_closeasm(outf,TRUE); outf=NULL; @@ -321,8 +321,8 @@ static short lastfile; } else { FILE *fp=fopen(errfname,"a"); if (fp!=NULL) { - if (errstart>=0 && errstart!=errline) - fprintf(fp,"%s(%d -- %d) : %s %03d: ",inpfname,errstart,errline,pre,(int)number); + if (start>=0 && start!=errline) + fprintf(fp,"%s(%d -- %d) : %s %03d: ",inpfname,start,errline,pre,(int)number); else fprintf(fp,"%s(%d) : %s %03d: ",inpfname,errline,pre,(int)number); vfprintf(fp,msg,argptr); @@ -346,7 +346,7 @@ static short lastfile; errline=-1; /* check whether we are seeing many errors on the same line */ - if ((errstart<0 && lastline!=fline) || lastlinefline || fcurrent!=lastfile) + if ((start<0 && lastline!=fline) || lastlinefline || fcurrent!=lastfile) errorcount=0; lastline=fline; lastfile=fcurrent; From 44a8c5c76f13d58c77cf1ff7d16e98dcea3def02 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 6 Mar 2021 20:22:19 +0700 Subject: [PATCH 2/3] Fix wrongly printed starting line number for one of the warnings in `__pragma` tests This was another manifestation of the bug reported in #398. --- source/compiler/tests/__pragma.meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/tests/__pragma.meta b/source/compiler/tests/__pragma.meta index 71a1ace..e317656 100644 --- a/source/compiler/tests/__pragma.meta +++ b/source/compiler/tests/__pragma.meta @@ -14,6 +14,6 @@ __pragma.pwn(67) : warning 207: unknown #pragma __pragma.pwn(68) : warning 207: unknown #pragma __pragma.pwn(33) : warning 203: symbol is never used: "f" __pragma.pwn(29) : warning 204: symbol is assigned a value that is never used: "e" -__pragma.pwn(29 -- 70) : warning 203: symbol is never used: "operator~(Tag:)" +__pragma.pwn(70) : warning 203: symbol is never used: "operator~(Tag:)" """ } From 74bb2b345047288282ecf68273e975927088c2f6 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 6 Mar 2021 20:54:06 +0700 Subject: [PATCH 3/3] Add tests --- source/compiler/tests/gh_398.inc | 4 ++++ source/compiler/tests/gh_398.meta | 7 +++++++ source/compiler/tests/gh_398.pwn | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 source/compiler/tests/gh_398.inc create mode 100644 source/compiler/tests/gh_398.meta create mode 100644 source/compiler/tests/gh_398.pwn diff --git a/source/compiler/tests/gh_398.inc b/source/compiler/tests/gh_398.inc new file mode 100644 index 0000000..c5d510b --- /dev/null +++ b/source/compiler/tests/gh_398.inc @@ -0,0 +1,4 @@ +/* 3 empty lines */ + + +new a, b;// <= line 4 diff --git a/source/compiler/tests/gh_398.meta b/source/compiler/tests/gh_398.meta new file mode 100644 index 0000000..ec5dcf3 --- /dev/null +++ b/source/compiler/tests/gh_398.meta @@ -0,0 +1,7 @@ +{ + 'test_type': 'output_check', + 'errors': """ +gh_398.pwn(4) : warning 203: symbol is never used: "a" +gh_398.pwn(4) : warning 203: symbol is never used: "b" + """ +} diff --git a/source/compiler/tests/gh_398.pwn b/source/compiler/tests/gh_398.pwn new file mode 100644 index 0000000..5d6d584 --- /dev/null +++ b/source/compiler/tests/gh_398.pwn @@ -0,0 +1,2 @@ +#include "gh_398.inc" +main(){}