diff options
author | Jörg Mayer <jmayer@loplof.de> | 2014-01-19 17:59:20 +0000 |
---|---|---|
committer | Jörg Mayer <jmayer@loplof.de> | 2014-01-19 17:59:20 +0000 |
commit | a8002aa0b74e747d835889d8897c5733ba052ee0 (patch) | |
tree | 7ed8f0e629fe3f35035f0fb3ab9ea01a9787506b /tools/lemon | |
parent | a0df200a8407164c654051bae921f494bf8bb454 (diff) |
Fix two coverity messages:
*** CID 718534: Dereference before null check (REVERSE_INULL)
/tools/lemon/lemon.c: 3425 in translate_code()
3419 rp->rhs[i]->index,i-rp->nrhs+1);
3420 }else{
3421 /* No destructor defined for this term */
3422 }
3423 }
3424 }
>>> CID 718534: Dereference before null check (REVERSE_INULL)
>>> Null-checking "rp->code" suggests that it may be null, but it has already been
+dereferenced on all paths leading to the check.
3425 if( rp->code ){
3426 cp = append_str(0,0,0,0);
3427 rp->code = Strsafe(cp?cp:"");
3428 }
3429 }
3430
*** CID 1156989: Out-of-bounds read (OVERRUN)
/tools/lemon/lemon.c: 3139 in tplt_xfer()
3133 int i, iStart;
3134 char line[LINESIZE];
3135 while( fgets(line,LINESIZE,in) && (line[0]!='%' || line[1]!='%') ){
3136 (*lineno)++;
3137 iStart = 0;
3138 if( name ){
>>> CID 1156989: Out-of-bounds read (OVERRUN)
>>> Overrunning array "line" of 1000 bytes at byte offset 1000 using index "i"
+(which evaluates to 1000).
3139 for(i=0; line[i] && i<LINESIZE; i++){
3140 if( line[i]=='P' && i<(LINESIZE-5) && strncmp(&line[i],"Parse",5)==0
3141 && (i==0 || !safe_isalpha(line[i-1]))
3142 ){
3143 if( i>iStart ) fprintf(out,"%.*s",i-iStart,&line[iStart]);
3144 fprintf(out,"%s",name);
svn path=/trunk/; revision=54849
Diffstat (limited to 'tools/lemon')
-rw-r--r-- | tools/lemon/lemon.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 7bc9f746c6..d87cb36ae0 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -3136,7 +3136,7 @@ PRIVATE void tplt_xfer(const char *name, FILE *in, FILE *out, int *lineno) (*lineno)++; iStart = 0; if( name ){ - for(i=0; line[i] && i<LINESIZE; i++){ + for(i=0; i<LINESIZE && line[i]; i++){ if( line[i]=='P' && i<(LINESIZE-5) && strncmp(&line[i],"Parse",5)==0 && (i==0 || !safe_isalpha(line[i-1])) ){ @@ -3422,10 +3422,8 @@ PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ } } } - if( rp->code ){ - cp = append_str(0,0,0,0); - rp->code = Strsafe(cp?cp:""); - } + cp = append_str(0,0,0,0); + rp->code = Strsafe(cp?cp:""); } /* |