Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
detecting repeating keys in record (memory leak)
  • Loading branch information
Ilya Dogolazky committed Jul 28, 2011
1 parent 57137ad commit 6016adb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/datalang.y
Expand Up @@ -25,7 +25,7 @@

%{
int iodata_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner) ;
void iodata_error(YYLTYPE* locp, iodata::parser* context, const char* err) ;
void iodata_error(YYLTYPE* locp, iodata::parser* context, const char* format, ...) ;
#define scanner context->scanner
%}

Expand Down Expand Up @@ -66,7 +66,21 @@ record : { $$ = new iodata::record }
;

record_ : TIDENT '=' item { ($$=new iodata::record)->add(*$1,$3) ; delete $1 }
| TIDENT '=' item ',' record_ { ($$=$5)->add(*$1,$3) ; delete $1 /* XXX replace? */ }
| TIDENT '=' item ',' record_ {
if ($5->key_present(*$1))
{
iodata_error(&yylloc, context, "key '%s' redefined", $1->c_str()) ;
delete $1 ;
delete $3 ;
delete $5 ;
YYABORT ;
}
else
{
($$=$5)->add(*$1,$3) ;
delete $1 ;
}
}
;

array : item { ($$=new iodata::array)->add($1) }
Expand Down
2 changes: 2 additions & 0 deletions src/iodata.h
Expand Up @@ -136,6 +136,8 @@ namespace iodata
void add(const string &k, bitmask_t v, const bit_codec *c) { x[k] = new bitmask(v,c); }
void add(const string &k, const string &v) { x[k] = new bytes(v) ; }

bool key_present(const string &k) { return x.count(k)>0 ; }

// void throw_unless_record() { } ;
void plain_output(ostream &os, const string &prefix) const ;
virtual ~record() ;
Expand Down

0 comments on commit 6016adb

Please sign in to comment.