Changeset f487962 for src/Parser/lex.cc


Ignore:
Timestamp:
Aug 18, 2016, 10:37:38 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
8b7ee09
Parents:
9b967914
Message:

fix storage leaks in lexer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.cc

    r9b967914 rf487962  
    14691469 * Created On       : Sat Sep 22 08:58:10 2001
    14701470 * Last Modified By : Peter A. Buhr
    1471  * Last Modified On : Tue Aug 16 22:34:31 2016
    1472  * Update Count     : 460
     1471 * Last Modified On : Thu Aug 18 22:17:30 2016
     1472 * Update Count     : 472
    14731473 */
    14741474#line 20 "lex.ll"
     
    14801480
    14811481#include <string>
     1482#include <cstdio>                                                                               // FILENAME_MAX
    14821483
    14831484#include "lex.h"
     
    14941495#define RETURN_STR(x)           yylval.tok.str = strtext; RETURN_LOCN( x )
    14951496
    1496 #define WHITE_RETURN(x)                                                                 // do nothing
     1497#define WHITE_RETURN(x)         // do nothing
    14971498#define NEWLINE_RETURN()        WHITE_RETURN( '\n' )
    14981499#define ASCIIOP_RETURN()        RETURN_CHAR( (int)yytext[0] ) // single character operator
    1499 #define NAMEDOP_RETURN(x)       RETURN_VAL( x )                         // multichar operator, with a name
     1500#define NAMEDOP_RETURN(x)       RETURN_CHAR( x )                        // multichar operator, with a name
    15001501#define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL( x ) // numeric constant
    15011502#define KEYWORD_RETURN(x)       RETURN_CHAR( x )                        // keyword
     
    15311532
    15321533
    1533 #line 1534 "Parser/lex.cc"
     1534#line 1535 "Parser/lex.cc"
    15341535
    15351536#define INITIAL 0
     
    17231724        register int yy_act;
    17241725   
    1725 #line 138 "lex.ll"
     1726#line 139 "lex.ll"
    17261727
    17271728                                   /* line directives */
    1728 #line 1729 "Parser/lex.cc"
     1729#line 1730 "Parser/lex.cc"
    17291730
    17301731        if ( !(yy_init) )
     
    18231824/* rule 1 can match eol */
    18241825YY_RULE_SETUP
    1825 #line 140 "lex.ll"
     1826#line 141 "lex.ll"
    18261827{
    18271828        /* " stop highlighting */
     1829        static char *filename[FILENAME_MAX];                            // temporarily store current source-file name
    18281830        char *end_num;
    18291831        char *begin_string, *end_string;
    1830         char *filename;
    18311832        long lineno, length;
    18321833        lineno = strtol( yytext + 1, &end_num, 0 );
    18331834        begin_string = strchr( end_num, '"' );
    1834         if ( begin_string ) {
    1835                 end_string = strchr( begin_string + 1, '"' );
    1836                 if ( end_string ) {
    1837                         length = end_string - begin_string - 1;
    1838                         filename = new char[ length + 1 ];
    1839                         memcpy( filename, begin_string + 1, length );
    1840                         filename[ length ] = '\0';
    1841                         //std::cout << "file " << filename << " line " << lineno << std::endl;
    1842                         yylineno = lineno;
    1843                         yyfilename = filename;
    1844                 } // if
     1835        if ( begin_string ) {                                                           // file name ?
     1836                end_string = strchr( begin_string + 1, '"' );   // look for ending delimiter
     1837                assert( end_string );                                                   // closing quote ?
     1838                length = end_string - begin_string - 1;                 // file-name length without quotes or sentinel
     1839                assert( length < FILENAME_MAX );                                // room for sentinel ?
     1840                memcpy( &filename, begin_string + 1, length );  // copy file name from yytext
     1841                filename[ length ] = '\0';                                              // terminate string with sentinel
     1842                //std::cout << "file " << filename << " line " << lineno << std::endl;
     1843                yylineno = lineno;
     1844                yyfilename = filename[0];
    18451845        } // if
    18461846}
Note: See TracChangeset for help on using the changeset viewer.