diff options
author | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2015-07-06 09:02:41 +0200 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2015-11-23 09:32:38 +0000 |
commit | e0af790aac61a9e62bd3558fee07235bb504ff59 (patch) | |
tree | 711a7646d4305f06b1decc8f63ab22712536b44f /tools | |
parent | 815b7fe728eadd15d9708afbc236b6399e4c46a0 (diff) |
lemon (tools): Fix Dereference of null pointer found by Clang analyzer
Change-Id: I6be51833b4268dbfde5c78820004a4714779b0c5
Reviewed-on: https://code.wireshark.org/review/9515
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lemon/lemon.c | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index e091d2419a..c349dfab00 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -1019,8 +1019,10 @@ void FindLinks(struct lemon *lemp) ** which the link is attached. */ for(i=0; i<lemp->nstate; i++){ stp = lemp->sorted[i]; - for(cfp=stp->cfp; cfp; cfp=cfp->next){ - cfp->stp = stp; + if(stp){ + for(cfp=stp->cfp; cfp; cfp=cfp->next){ + cfp->stp = stp; + } } } @@ -1028,10 +1030,12 @@ void FindLinks(struct lemon *lemp) ** links are used in the follow-set computation. */ for(i=0; i<lemp->nstate; i++){ stp = lemp->sorted[i]; - for(cfp=stp->cfp; cfp; cfp=cfp->next){ - for(plp=cfp->bplp; plp; plp=plp->next){ - other = plp->cfp; - Plink_add(&other->fplp,cfp); + if(stp){ + for(cfp=stp->cfp; cfp; cfp=cfp->next){ + for(plp=cfp->bplp; plp; plp=plp->next){ + other = plp->cfp; + Plink_add(&other->fplp,cfp); + } } } } @@ -1051,24 +1055,28 @@ void FindFollowSets(struct lemon *lemp) int change; for(i=0; i<lemp->nstate; i++){ - for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){ - cfp->status = INCOMPLETE; + if(lemp->sorted[i]){ + for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){ + cfp->status = INCOMPLETE; + } } } do{ progress = 0; for(i=0; i<lemp->nstate; i++){ - for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){ - if( cfp->status==COMPLETE ) continue; - for(plp=cfp->fplp; plp; plp=plp->next){ - change = SetUnion(plp->cfp->fws,cfp->fws); - if( change ){ - plp->cfp->status = INCOMPLETE; - progress = 1; + if(lemp->sorted[i]){ + for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){ + if( cfp->status==COMPLETE ) continue; + for(plp=cfp->fplp; plp; plp=plp->next){ + change = SetUnion(plp->cfp->fws,cfp->fws); + if( change ){ + plp->cfp->status = INCOMPLETE; + progress = 1; + } } + cfp->status = COMPLETE; } - cfp->status = COMPLETE; } } }while( progress ); @@ -1092,13 +1100,15 @@ void FindActions(struct lemon *lemp) */ for(i=0; i<lemp->nstate; i++){ /* Loop over all states */ stp = lemp->sorted[i]; - for(cfp=stp->cfp; cfp; cfp=cfp->next){ /* Loop over all configurations */ - if( cfp->rp->nrhs==cfp->dot ){ /* Is dot at extreme right? */ - for(j=0; j<lemp->nterminal; j++){ - if( SetFind(cfp->fws,j) ){ - /* Add a reduce action to the state "stp" which will reduce by the - ** rule "cfp->rp" if the lookahead symbol is "lemp->symbols[j]" */ - Action_add(&stp->ap,REDUCE,lemp->symbols[j],(char *)cfp->rp); + if(stp){ + for(cfp=stp->cfp; cfp; cfp=cfp->next){ /* Loop over all configurations */ + if( cfp->rp->nrhs==cfp->dot ){ /* Is dot at extreme right? */ + for(j=0; j<lemp->nterminal; j++){ + if( SetFind(cfp->fws,j) ){ + /* Add a reduce action to the state "stp" which will reduce by the + ** rule "cfp->rp" if the lookahead symbol is "lemp->symbols[j]" */ + Action_add(&stp->ap,REDUCE,lemp->symbols[j],(char *)cfp->rp); + } } } } |