Text   |  XML   |  ReML   |   Visible Warnings:

Ignored Return Value  at lemon.c:2574

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

Parse

(/home/sate/Testcases/c/cve/wireshark-1.2.0/tools/lemon/lemon.c)expand/collapse
Show more  
 2539  void Parse(struct lemon *gp)
 2540  {
 2541    struct pstate ps;
 2542    FILE *fp;
 2543    char *filebuf;
 2544    long filesize;
 2545    int lineno;
 2546    char c;
 2547    char *cp, *nextcp;
 2548    int startline = 0;
 2549   
 2550    memset(&ps, '\0', sizeof(ps));
 2551    ps.gp = gp;
 2552    ps.filename = gp->filename;
 2553    ps.errorcnt = 0;
 2554    ps.state = INITIALIZE;
 2555    ps.prevrule = NULL;
 2556    ps.preccounter = 0;
 2557    ps.lastrule = NULL;
 2558    ps.firstrule = NULL;
 2559    ps.lhs = NULL;
 2560    ps.nrhs = 0;
 2561    ps.lhsalias = NULL;
 2562    ps.declkeyword = NULL;
 2563    ps.declargslot = NULL;
 2564    ps.declassoc = UNK;
 2565    ps.fallback = NULL;
 2566   
 2567    /* Begin by reading the input file */
 2568    fp = fopen(ps.filename,"rb");
 2569    if( fp==0 ){
 2570      ErrorMsg(ps.filename,0,"Can't open this file for reading.");
 2571      gp->errorcnt++;
 2572      return;
 2573    }
 2574    fseek(fp,0,2);
 2575    filesize = ftell(fp);
 2576    rewind(fp);
 2577    /* XXX - what if filesize is bigger than the maximum size_t value? */
 2578    filebuf = (char *)malloc( filesize+1 );
 2579    if( filebuf==0 ){
 2580      ErrorMsg(ps.filename,0,"Can't allocate %ld of memory to hold this file.",
 2581        filesize+1);
 2582      gp->errorcnt++;
 2583      return;
 2584    }
 2585    if( fread(filebuf,1,filesize,fp)!=(size_t)filesize ){
 2586      ErrorMsg(ps.filename,0,"Can't read in all %ld bytes of this file.",
 2587        filesize);
 2588      free(filebuf);
 2589      gp->errorcnt++;
 2590      return;
 2591    }
 2592    fclose(fp);
 2593    filebuf[filesize] = 0;
 2594   
 2595    /* Make an initial pass through the file to handle %ifdef and %ifndef */
 2596    preprocess_input(filebuf);
 2597   
 2598    /* Now scan the text of the input file */
 2599    lineno = 1;
 2600    for(cp=filebuf; (c= *cp)!=0; ){
 2601      if( c=='\n' ) lineno++;              /* Keep track of the line number */
 2602      if( safe_isspace(c) ){ cp++; continue; }  /* Skip all white space */
 2603      if( c=='/' && cp[1]=='/' ){          /* Skip C++ style comments */
 2604        cp+=2;
 2605        while( (c= *cp)!=0 && c!='\n' ) cp++;
 2606        continue;
 2607      }
 2608      if( c=='/' && cp[1]=='*' ){          /* Skip C style comments */
 2609        cp+=2;
 2610        while( (c= *cp)!=0 && (c!='/' || cp[-1]!='*') ){
 2611          if( c=='\n' ) lineno++;
 2612          cp++;
 2613        }
 2614        if( c ) cp++;
 2615        continue;
 2616      }
 2617      ps.tokenstart = cp;                /* Mark the beginning of the token */
 2618      ps.tokenlineno = lineno;           /* Linenumber on which token begins */
 2619      if( c=='\"' ){                     /* String literals */
 2620        cp++;
 2621        while( (c= *cp)!=0 && c!='\"' ){
 2622          if( c=='\n' ) lineno++;
 2623          cp++;
 2624        }
 2625        if( c==0 ){
 2626          ErrorMsg(ps.filename,startline,
 2627  "String starting on this line is not terminated before the end of the file.");
 2628          ps.errorcnt++;
 2629          nextcp = cp;
 2630        }else{
 2631          nextcp = cp+1;
 2632        }
 2633      }else if( c=='{' ){               /* A block of C code */
 2634        int level;
 2635        cp++;
 2636        for(level=1; (c= *cp)!=0 && (level>1 || c!='}'); cp++){
 2637          if( c=='\n' ) lineno++;
 2638          else if( c=='{' ) level++;
 2639          else if( c=='}' ) level--;
 2640          else if( c=='/' && cp[1]=='*' ){  /* Skip comments */
 2641            char prevc;
 2642            cp = &cp[2];
 2643            prevc = 0;
 2644            while( (c= *cp)!=0 && (c!='/' || prevc!='*') ){
 2645              if( c=='\n' ) lineno++;
 2646              prevc = c;
 2647              cp++;
 2648            }
 2649          }else if( c=='/' && cp[1]=='/' ){  /* Skip C++ style comments too */
 2650            cp = &cp[2];
 2651            while( (c= *cp)!=0 && c!='\n' ) cp++;
 2652            if( c ) lineno++;
 2653          }else if( c=='\'' || c=='\"' ){    /* String a character literals */
 2654            char startchar, prevc;
 2655            startchar = c;
 2656            prevc = 0;
 2657            for(cp++; (c= *cp)!=0 && (c!=startchar || prevc=='\\'); cp++){
 2658              if( c=='\n' ) lineno++;
 2659              if( prevc=='\\' ) prevc = 0;
 2660              else              prevc = c;
 2661            }
 2662          }
 2663        }
 2664        if( c==0 ){
 2665          ErrorMsg(ps.filename,ps.tokenlineno,
 2666  "C code starting on this line is not terminated before the end of the file.");
 2667          ps.errorcnt++;
 2668          nextcp = cp;
 2669        }else{
 2670          nextcp = cp+1;
 2671        }
 2672      }else if( safe_isalnum(c) ){          /* Identifiers */
 2673        while( (c= *cp)!=0 && (safe_isalnum(c) || c=='_') ) cp++;
 2674        nextcp = cp;
 2675      }else if( c==':' && cp[1]==':' && cp[2]=='=' ){ /* The operator "::=" */
 2676        cp += 3;
 2677        nextcp = cp;
 2678      }else if( (c=='/' || c=='|') && safe_isalpha(cp[1]) ){
 2679        cp += 2;
 2680        while( (c = *cp)!=0 && (safe_isalnum(c) || c=='_') ) cp++;
 2681        nextcp = cp;
 2682      }else{                          /* All other (one character) operators */
 2683        cp++;
 2684        nextcp = cp;
 2685      }
 2686      c = *cp;
 2687      *cp = 0;                        /* Null terminate the token */
 2688      parseonetoken(&ps);             /* Parse the token */
 2689      *cp = c;                        /* Restore the buffer */
 2690      cp = nextcp;
 2691    }
 2692    free(filebuf);                    /* Release the buffer after parsing */
 2693    gp->rule = ps.firstrule;
 2694    gp->errorcnt = ps.errorcnt;
 2695  }
Show more  




Change Warning 5504.35770 : Ignored Return Value

Priority:
State:
Finding:
Owner:
Note: