From bd133697fda8c9a74b3bed440edcff0f6c314ca5 Mon Sep 17 00:00:00 2001 From: Yashas Date: Sat, 30 Sep 2017 09:24:23 +0530 Subject: [PATCH 1/2] remove extra new lines from #warning and #pragma deprecated The `#warning` and `#pragma deprecated` directives print the new line characters which are part of the user entered string. As the message formats for both these already contain a new line character at the end, the aforementioned directives printed two new lines. This commit adds code to discard the new line characters from user string. --- source/compiler/sc2.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 18a9caa..2eaffda 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1122,8 +1122,10 @@ static int command(void) while (*lptr<=' ' && *lptr!='\0') lptr++; pc_deprecate=(char*)malloc(strlen((char*)lptr)+1); - if (pc_deprecate!=NULL) - strcpy(pc_deprecate,(char*)lptr); + if (pc_deprecate!=NULL) { + strcpy(pc_deprecate,lptr); + pc_deprecate[strcspn(pc_deprecate,"\r\n")]='\0'; + } /* if */ lptr=(unsigned char*)strchr((char*)lptr,'\0'); /* skip to end (ignore "extra characters on line") */ } else if (strcmp(str,"dynamic")==0) { preproc_expr(&pc_stksize,NULL); @@ -1490,8 +1492,13 @@ static int command(void) case tpWARNING: while (*lptr<=' ' && *lptr!='\0') lptr++; - if (!SKIPPING) - error(237,lptr); /* user warning */ + if (!SKIPPING) { + char *usermsg=(char*)malloc(strlen(lptr)+1); + strcpy(usermsg,lptr); + usermsg[strcspn(usermsg,"\r\n")]='\0'; + error(237,usermsg); /* user warning */ + free(usermsg); + } /* if */ break; default: error(31); /* unknown compiler directive */ From 13314369a55db1121bc364e004a7b8f2c8c9bf84 Mon Sep 17 00:00:00 2001 From: Yashas Date: Sat, 30 Sep 2017 09:33:47 +0530 Subject: [PATCH 2/2] handle allocation failure in the previous commit --- source/compiler/sc2.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 2eaffda..4c718d3 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1494,10 +1494,14 @@ static int command(void) lptr++; if (!SKIPPING) { char *usermsg=(char*)malloc(strlen(lptr)+1); - strcpy(usermsg,lptr); - usermsg[strcspn(usermsg,"\r\n")]='\0'; - error(237,usermsg); /* user warning */ - free(usermsg); + if(usermsg!=NULL) { + strcpy(usermsg,lptr); + usermsg[strcspn(usermsg,"\r\n")]='\0'; + error(237,usermsg); /* user warning */ + free(usermsg); + } else { + error(237,lptr); + } /* if */ } /* if */ break; default: