projects
/
fw
/
sdcc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fixed bug#680076
[fw/sdcc]
/
src
/
SDCC.y
diff --git
a/src/SDCC.y
b/src/SDCC.y
index 83409a13eee5b778e5622d262a60f7db466a8d51..bc7137e668b9a95f9d78f40a2fe3ff8c28da72fe 100644
(file)
--- a/
src/SDCC.y
+++ b/
src/SDCC.y
@@
-34,6
+34,7
@@
#include "port.h"
#include "newalloc.h"
#include "SDCCerr.h"
#include "port.h"
#include "newalloc.h"
#include "SDCCerr.h"
+#include "SDCCutil.h"
extern int yyerror (char *);
extern FILE *yyin;
extern int yyerror (char *);
extern FILE *yyin;
@@
-868,11
+869,13
@@
opt_assign_expr
}
| {
if (cenum) {
}
| {
if (cenum) {
- sprintf(lbuff,"%d",(int) floatFromVal(cenum)+1);
+ SNPRINTF(lbuff, sizeof(lbuff),
+ "%d",(int) floatFromVal(cenum)+1);
$$ = cenum = constVal(lbuff);
}
else {
$$ = cenum = constVal(lbuff);
}
else {
- sprintf(lbuff,"%d",0);
+ SNPRINTF(lbuff, sizeof(lbuff),
+ "%d",0);
$$ = cenum = constVal(lbuff);
}
}
$$ = cenum = constVal(lbuff);
}
}
@@
-1015,6
+1018,7
@@
pointer
default:
// this could be just "constant"
// werror(W_PTR_TYPE_INVALID);
default:
// this could be just "constant"
// werror(W_PTR_TYPE_INVALID);
+ ;
}
}
else
}
}
else
@@
-1101,9
+1105,13
@@
type_name
/* go to the end of the list */
sym_link *p;
pointerTypes($2,$1);
/* go to the end of the list */
sym_link *p;
pointerTypes($2,$1);
- for ( p = $2 ; p->next ; p=p->next);
- p->next = $1 ;
- $$ = $2 ;
+ for ( p = $2 ; p && p->next ; p=p->next);
+ if (!p) {
+ werror(E_SYNTAX_ERROR, yytext);
+ } else {
+ p->next = $1 ;
+ }
+ $$ = $2 ;
}
;
}
;
@@
-1146,19
+1154,32
@@
abstract_declarator2
// $1 must be a pointer to a function
sym_link *p=newLink();
DCL_TYPE(p) = FUNCTION;
// $1 must be a pointer to a function
sym_link *p=newLink();
DCL_TYPE(p) = FUNCTION;
+ if (!$1) {
+ // ((void (code *) ()) 0) ()
+ $1=newLink();
+ DCL_TYPE($1)=CPOINTER;
+ $$ = $1;
+ }
$1->next=p;
}
| abstract_declarator2 '(' parameter_type_list ')' {
$1->next=p;
}
| abstract_declarator2 '(' parameter_type_list ')' {
- if (!IS_VOID($3->type)) {
+ if (!IS_VOID($3->
e
type)) {
// this is nonsense, so let's just burp something
werror(E_TOO_FEW_PARMS);
} else {
// $1 must be a pointer to a function
sym_link *p=newLink();
DCL_TYPE(p) = FUNCTION;
// this is nonsense, so let's just burp something
werror(E_TOO_FEW_PARMS);
} else {
// $1 must be a pointer to a function
sym_link *p=newLink();
DCL_TYPE(p) = FUNCTION;
+ if (!$1) {
+ // ((void (code *) (void)) 0) ()
+ $1=newLink();
+ DCL_TYPE($1)=CPOINTER;
+ $$ = $1;
+ }
$1->next=p;
}
}
$1->next=p;
}
}
+ ;
initializer
: assignment_expr { $$ = newiList(INIT_NODE,$1); }
initializer
: assignment_expr { $$ = newiList(INIT_NODE,$1); }
@@
-1180,8
+1201,7
@@
statement
| jump_statement
| INLINEASM ';' {
ast *ex = newNode(INLINEASM,NULL,NULL);
| jump_statement
| INLINEASM ';' {
ast *ex = newNode(INLINEASM,NULL,NULL);
- ex->values.inlineasm = malloc(strlen($1)+1);
- strcpy(ex->values.inlineasm,$1);
+ ex->values.inlineasm = strdup($1);
$$ = ex;
}
;
$$ = ex;
}
;
@@
-1275,7
+1295,8
@@
selection_statement
ex->values.switchVals.swNum = swLabel ;
/* now create the label */
ex->values.switchVals.swNum = swLabel ;
/* now create the label */
- sprintf(lbuff,"_swBrk_%d",swLabel++);
+ SNPRINTF(lbuff, sizeof(lbuff),
+ "_swBrk_%d",swLabel++);
$<sym>$ = newSymbol(lbuff,NestLevel);
/* put label in the break stack */
STACK_PUSH(breakStack,$<sym>$);
$<sym>$ = newSymbol(lbuff,NestLevel);
/* put label in the break stack */
STACK_PUSH(breakStack,$<sym>$);
@@
-1291,45
+1312,49
@@
selection_statement
while : WHILE { /* create and push the continue , break & body labels */
static int Lblnum = 0 ;
/* continue */
while : WHILE { /* create and push the continue , break & body labels */
static int Lblnum = 0 ;
/* continue */
-
sprintf (lbuff,
"_whilecontinue_%d",Lblnum);
+
SNPRINTF (lbuff, sizeof(lbuff),
"_whilecontinue_%d",Lblnum);
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
-
sprintf (lbuff,
"_whilebreak_%d",Lblnum);
+
SNPRINTF (lbuff, sizeof(lbuff),
"_whilebreak_%d",Lblnum);
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* body */
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* body */
-
sprintf (lbuff,
"_whilebody_%d",Lblnum++);
+
SNPRINTF (lbuff, sizeof(lbuff),
"_whilebody_%d",Lblnum++);
$$ = newSymbol(lbuff,NestLevel);
}
$$ = newSymbol(lbuff,NestLevel);
}
+ ;
do : DO { /* create and push the continue , break & body Labels */
static int Lblnum = 0 ;
/* continue */
do : DO { /* create and push the continue , break & body Labels */
static int Lblnum = 0 ;
/* continue */
-
sprintf(lbuff,
"_docontinue_%d",Lblnum);
+
SNPRINTF(lbuff, sizeof(lbuff),
"_docontinue_%d",Lblnum);
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
-
sprintf (lbuff,
"_dobreak_%d",Lblnum);
+
SNPRINTF(lbuff, sizeof(lbuff),
"_dobreak_%d",Lblnum);
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* do body */
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* do body */
-
sprintf (lbuff,
"_dobody_%d",Lblnum++);
+
SNPRINTF(lbuff, sizeof(lbuff),
"_dobody_%d",Lblnum++);
$$ = newSymbol (lbuff,NestLevel);
}
$$ = newSymbol (lbuff,NestLevel);
}
+ ;
+
for : FOR { /* create & push continue, break & body labels */
static int Lblnum = 0 ;
/* continue */
for : FOR { /* create & push continue, break & body labels */
static int Lblnum = 0 ;
/* continue */
-
sprintf (lbuff,
"_forcontinue_%d",Lblnum);
+
SNPRINTF(lbuff, sizeof(lbuff),
"_forcontinue_%d",Lblnum);
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
-
sprintf (lbuff,
"_forbreak_%d",Lblnum);
+
SNPRINTF(lbuff, sizeof(lbuff),
"_forbreak_%d",Lblnum);
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* body */
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* body */
-
sprintf (lbuff,
"_forbody_%d",Lblnum);
+
SNPRINTF(lbuff, sizeof(lbuff),
"_forbody_%d",Lblnum);
$$ = newSymbol(lbuff,NestLevel);
/* condition */
$$ = newSymbol(lbuff,NestLevel);
/* condition */
-
sprintf (lbuff,
"_forcond_%d",Lblnum++);
+
SNPRINTF(lbuff, sizeof(lbuff),
"_forcond_%d",Lblnum++);
STACK_PUSH(forStack,newSymbol(lbuff,NestLevel));
}
STACK_PUSH(forStack,newSymbol(lbuff,NestLevel));
}
+ ;
iteration_statement
: while '(' expr ')' statement
iteration_statement
: while '(' expr ')' statement