From: Peter Verthez Date: Sun, 2 Dec 2001 09:25:05 +0000 (+0000) Subject: Reverted to previous yylval union declaration. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=71b64299d1bd7a95bebf6173c5624cb9a1dd1851;p=gedcom-parse.git Reverted to previous yylval union declaration. Proper checks for maximum lengths. --- diff --git a/gedcom.y b/gedcom.y index 5416d50..3364269 100644 --- a/gedcom.y +++ b/gedcom.y @@ -124,8 +124,8 @@ /* General notes: - - The syntax analysis doesn't handle the contents of the line values - or their encoding; this is done in the semantic analysis. + - The syntax analysis doesn't handle the contents of the line values; + this is done in the semantic analysis. */ @@ -139,9 +139,10 @@ int fail = 0; int compat_enabled = 1; int gedcom_high_level_debug = 0; int compatibility = 0; -MECHANISM error_mechanism=IMMED_FAIL; -char string_buf[MAXGEDCLINELEN*4+1]; -char *string_buf_ptr; +MECHANISM error_mechanism = IMMED_FAIL; + +char line_item_buf[MAXGEDCLINELEN * UTF_FACTOR + 1]; +char *line_item_buf_ptr; enum _COMPAT { C_FTREE = 0x01 @@ -222,9 +223,7 @@ int compat_mode(int flags); %} %union { - int level; - char *pointer; - char *tag; + int number; char *string; } @@ -232,145 +231,145 @@ int compat_mode(int flags); %expect 300 %token BADTOKEN -%token OPEN +%token OPEN %token CLOSE %token ESCAPE %token DELIM %token ANYCHAR -%token POINTER -%token USERTAG -%token TAG_ABBR -%token TAG_ADDR -%token TAG_ADR1 -%token TAG_ADR2 -%token TAG_ADOP -%token TAG_AFN -%token TAG_AGE -%token TAG_AGNC -%token TAG_ALIA -%token TAG_ANCE -%token TAG_ANCI -%token TAG_ANUL -%token TAG_ASSO -%token TAG_AUTH -%token TAG_BAPL -%token TAG_BAPM -%token TAG_BARM -%token TAG_BASM -%token TAG_BIRT -%token TAG_BLES -%token TAG_BLOB -%token TAG_BURI -%token TAG_CALN -%token TAG_CAST -%token TAG_CAUS -%token TAG_CENS -%token TAG_CHAN -%token TAG_CHAR -%token TAG_CHIL -%token TAG_CHR -%token TAG_CHRA -%token TAG_CITY -%token TAG_CONC -%token TAG_CONF -%token TAG_CONL -%token TAG_CONT -%token TAG_COPR -%token TAG_CORP -%token TAG_CREM -%token TAG_CTRY -%token TAG_DATA -%token TAG_DATE -%token TAG_DEAT -%token TAG_DESC -%token TAG_DESI -%token TAG_DEST -%token TAG_DIV -%token TAG_DIVF -%token TAG_DSCR -%token TAG_EDUC -%token TAG_EMIG -%token TAG_ENDL -%token TAG_ENGA -%token TAG_EVEN -%token TAG_FAM -%token TAG_FAMC -%token TAG_FAMF -%token TAG_FAMS -%token TAG_FCOM -%token TAG_FILE -%token TAG_FORM -%token TAG_GEDC -%token TAG_GIVN -%token TAG_GRAD -%token TAG_HEAD -%token TAG_HUSB -%token TAG_IDNO -%token TAG_IMMI -%token TAG_INDI -%token TAG_LANG -%token TAG_LEGA -%token TAG_MARB -%token TAG_MARC -%token TAG_MARL -%token TAG_MARR -%token TAG_MARS -%token TAG_MEDI -%token TAG_NAME -%token TAG_NATI -%token TAG_NATU -%token TAG_NCHI -%token TAG_NICK -%token TAG_NMR -%token TAG_NOTE -%token TAG_NPFX -%token TAG_NSFX -%token TAG_OBJE -%token TAG_OCCU -%token TAG_ORDI -%token TAG_ORDN -%token TAG_PAGE -%token TAG_PEDI -%token TAG_PHON -%token TAG_PLAC -%token TAG_POST -%token TAG_PROB -%token TAG_PROP -%token TAG_PUBL -%token TAG_QUAY -%token TAG_REFN -%token TAG_RELA -%token TAG_RELI -%token TAG_REPO -%token TAG_RESI -%token TAG_RESN -%token TAG_RETI -%token TAG_RFN -%token TAG_RIN -%token TAG_ROLE -%token TAG_SEX -%token TAG_SLGC -%token TAG_SLGS -%token TAG_SOUR -%token TAG_SPFX -%token TAG_SSN -%token TAG_STAE -%token TAG_STAT -%token TAG_SUBM -%token TAG_SUBN -%token TAG_SURN -%token TAG_TEMP -%token TAG_TEXT -%token TAG_TIME -%token TAG_TITL -%token TAG_TRLR -%token TAG_TYPE -%token TAG_VERS -%token TAG_WIFE -%token TAG_WILL - -%type anystdtag -%type anytoptag +%token POINTER +%token USERTAG +%token TAG_ABBR +%token TAG_ADDR +%token TAG_ADR1 +%token TAG_ADR2 +%token TAG_ADOP +%token TAG_AFN +%token TAG_AGE +%token TAG_AGNC +%token TAG_ALIA +%token TAG_ANCE +%token TAG_ANCI +%token TAG_ANUL +%token TAG_ASSO +%token TAG_AUTH +%token TAG_BAPL +%token TAG_BAPM +%token TAG_BARM +%token TAG_BASM +%token TAG_BIRT +%token TAG_BLES +%token TAG_BLOB +%token TAG_BURI +%token TAG_CALN +%token TAG_CAST +%token TAG_CAUS +%token TAG_CENS +%token TAG_CHAN +%token TAG_CHAR +%token TAG_CHIL +%token TAG_CHR +%token TAG_CHRA +%token TAG_CITY +%token TAG_CONC +%token TAG_CONF +%token TAG_CONL +%token TAG_CONT +%token TAG_COPR +%token TAG_CORP +%token TAG_CREM +%token TAG_CTRY +%token TAG_DATA +%token TAG_DATE +%token TAG_DEAT +%token TAG_DESC +%token TAG_DESI +%token TAG_DEST +%token TAG_DIV +%token TAG_DIVF +%token TAG_DSCR +%token TAG_EDUC +%token TAG_EMIG +%token TAG_ENDL +%token TAG_ENGA +%token TAG_EVEN +%token TAG_FAM +%token TAG_FAMC +%token TAG_FAMF +%token TAG_FAMS +%token TAG_FCOM +%token TAG_FILE +%token TAG_FORM +%token TAG_GEDC +%token TAG_GIVN +%token TAG_GRAD +%token TAG_HEAD +%token TAG_HUSB +%token TAG_IDNO +%token TAG_IMMI +%token TAG_INDI +%token TAG_LANG +%token TAG_LEGA +%token TAG_MARB +%token TAG_MARC +%token TAG_MARL +%token TAG_MARR +%token TAG_MARS +%token TAG_MEDI +%token TAG_NAME +%token TAG_NATI +%token TAG_NATU +%token TAG_NCHI +%token TAG_NICK +%token TAG_NMR +%token TAG_NOTE +%token TAG_NPFX +%token TAG_NSFX +%token TAG_OBJE +%token TAG_OCCU +%token TAG_ORDI +%token TAG_ORDN +%token TAG_PAGE +%token TAG_PEDI +%token TAG_PHON +%token TAG_PLAC +%token TAG_POST +%token TAG_PROB +%token TAG_PROP +%token TAG_PUBL +%token TAG_QUAY +%token TAG_REFN +%token TAG_RELA +%token TAG_RELI +%token TAG_REPO +%token TAG_RESI +%token TAG_RESN +%token TAG_RETI +%token TAG_RFN +%token TAG_RIN +%token TAG_ROLE +%token TAG_SEX +%token TAG_SLGC +%token TAG_SLGS +%token TAG_SOUR +%token TAG_SPFX +%token TAG_SSN +%token TAG_STAE +%token TAG_STAT +%token TAG_SUBM +%token TAG_SUBN +%token TAG_SURN +%token TAG_TEMP +%token TAG_TEXT +%token TAG_TIME +%token TAG_TITL +%token TAG_TRLR +%token TAG_TYPE +%token TAG_VERS +%token TAG_WIFE +%token TAG_WILL + +%type anystdtag +%type anytoptag %type line_item %type mand_line_item %type note_line_item @@ -433,7 +432,8 @@ head_sub : head_sour_sect { OCCUR2(SOUR, 1, 1) } /* HEAD.SOUR */ head_sour_sect : OPEN DELIM TAG_SOUR mand_line_item { set_compatibility($4); - gedcom_debug_print("===Source: '%s'\n", $4); + gedcom_debug_print("===Source: '%s', '%s'\n", + $4, $3); START(SOUR) } head_sour_subs @@ -2125,40 +2125,34 @@ opt_line_item : /* empty */ { } ; line_item : anychar { size_t i; - CLEAR_BUFFER(string_buf); - string_buf_ptr = string_buf; + CLEAR_BUFFER(line_item_buf); + line_item_buf_ptr = line_item_buf; /* The following also takes care of '@@' */ if (!strncmp($1, "@@", 3)) - *string_buf_ptr++ = '@'; + *line_item_buf_ptr++ = '@'; else for (i=0; i < strlen($1); i++) - *string_buf_ptr++ = $1[i]; - $$ = string_buf; + *line_item_buf_ptr++ = $1[i]; + $$ = line_item_buf; } - | ESCAPE { CLEAR_BUFFER(string_buf); - string_buf_ptr = string_buf; + | ESCAPE { CLEAR_BUFFER(line_item_buf); + line_item_buf_ptr = line_item_buf; /* For now, ignore escapes */ - $$ = string_buf; + $$ = line_item_buf; } | line_item anychar - { if (strlen(string_buf) >= MAXGEDCLINELEN) { - gedcom_error("Line too long"); - YYERROR; - } - else { - size_t i; - /* The following also takes care of '@@' */ - if (!strncmp($2, "@@", 3)) - *string_buf_ptr++ = '@'; - else - for (i=0; i < strlen($2); i++) - *string_buf_ptr++ = $2[i]; - $$ = string_buf; - } + { size_t i; + /* The following also takes care of '@@' */ + if (!strncmp($2, "@@", 3)) + *line_item_buf_ptr++ = '@'; + else + for (i=0; i < strlen($2); i++) + *line_item_buf_ptr++ = $2[i]; + $$ = line_item_buf; } | line_item ESCAPE { /* For now, ignore escapes */ - $$ = string_buf; + $$ = line_item_buf; } ; @@ -2345,7 +2339,7 @@ anystdtag : TAG_ABBR /* Functions that handle the counting of subtags */ int* count_arrays[MAXGEDCLEVEL+1]; -char tag_stack[MAXGEDCLEVEL+1][MAXSTDTAGLENGTH+1]; +char tag_stack[MAXGEDCLEVEL+1][MAXSTDTAGLEN+1]; void push_countarray() { @@ -2368,7 +2362,7 @@ void push_countarray() void set_parenttag(char* tag) { - strncpy(tag_stack[count_level], tag, MAXSTDTAGLENGTH+1); + strncpy(tag_stack[count_level], tag, MAXSTDTAGLEN+1); } char* get_parenttag()