diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 7dd4f2ad0f535f2628543a28824c259b51227698..a04f6a6bab7366b598aad532a347a52b70eb8a43 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -10598,7 +10598,7 @@ new_literal( const char initial[], enum radix_t radix ) { attr = bool_encoded_e; break; } - return new_literal(initial, cbl_field_attr_t(constant_e | attr)); + return new_literal(initial, strlen(initial), cbl_field_attr_t(constant_e | attr)); } class is_elementary_type { // for INITIALIZE purposes @@ -11031,7 +11031,7 @@ void parser_add_declaratives( size_t n, cbl_declarative_t *declaratives) { cbl_field_t * new_literal( const literal_t& lit, enum cbl_field_attr_t attr ) { assert(lit.data[lit.len] == '\0'); - return new_literal(lit.data, attr); + return new_literal(lit.data, lit.len, attr); #if 0 cbl_field_t *field = new_temporary_imply(FldLiteralA); diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h index f0cb609f2caa84af39e108eacd88e00c2a25b054..ae62c9b741e36ca845ec969056286cf3558ed730 100644 --- a/gcc/cobol/parse_ante.h +++ b/gcc/cobol/parse_ante.h @@ -2135,6 +2135,11 @@ intrinsic_call_4( cbl_field_t *tgt, int token, * Local functions */ +static inline cbl_field_t * +new_literal( const char initial[] ) { + return new_literal( initial, strlen(initial) ); +} + cbl_refer_t * negate( cbl_refer_t * refer, bool neg = true ) { if( ! neg ) return refer; diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc index 95f6d2ac203b92e16a4594fc74674afd28fd0c24..03dd040569728108c0ff911fddd06b739af13e7f 100644 --- a/gcc/cobol/symbols.cc +++ b/gcc/cobol/symbols.cc @@ -2961,7 +2961,7 @@ new_temporary_add( enum cbl_field_type_t type ) { } static cbl_field_t * -new_literal_add( const char initial[], enum cbl_field_attr_t attr ) { +new_literal_add( const char initial[], uint32_t len, enum cbl_field_attr_t attr ) { static char empty[2] = "\0"; cbl_field_t *field = NULL; if( !(attr & quoted_e) ) @@ -2977,7 +2977,7 @@ new_literal_add( const char initial[], enum cbl_field_attr_t attr ) { field->attr |= attr; field->type = FldLiteralA; field->data.initial = initial[0]? initial : empty; - field->data.capacity = strlen(field->data.initial); + field->data.capacity = len; if( ! field->internalize() ) { @@ -2994,7 +2994,7 @@ new_literal_add( const char initial[], enum cbl_field_attr_t attr ) { static temporaries_t temporaries; cbl_field_t * -temporaries_t::literal( const char value[], cbl_field_attr_t attr ) { +temporaries_t::literal( const char value[], uint32_t len, cbl_field_attr_t attr ) { auto p = literals.find(value); if( p != literals.end() ) { cbl_field_t *field = p->second; @@ -3003,14 +3003,15 @@ temporaries_t::literal( const char value[], cbl_field_attr_t attr ) { __func__, __LINE__, field->data.initial, field->attr, attr); } + assert(field->data.capacity == len); return field; } - return literals[value] = new_literal_add(value, attr); + return literals[value] = new_literal_add(value, len, attr); } cbl_field_t * -new_literal( const char initial[], enum cbl_field_attr_t attr ) { - return temporaries.literal(initial, attr); +new_literal( const char initial[], uint32_t len, enum cbl_field_attr_t attr ) { + return temporaries.literal(initial, len, attr); } cbl_field_t * diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h index 8dca4279c7d983e1d15be25c2ab2919d15c724a8..ef23ab66b4aa541b9ab70dc8178e4ca3932ffcb6 100644 --- a/gcc/cobol/symbols.h +++ b/gcc/cobol/symbols.h @@ -1180,7 +1180,7 @@ size_t field_index( const cbl_field_t *f ); cbl_field_t * new_temporary_imply( enum cbl_field_type_t type ); // for parser cbl_field_t * new_temporary( enum cbl_field_type_t type ); -cbl_field_t * new_literal( const char initial[], +cbl_field_t * new_literal( const char initial[], uint32_t len, enum cbl_field_attr_t attr = none_e ); class temporaries_t { @@ -1188,7 +1188,7 @@ class temporaries_t { typedef std::set<cbl_field_t *> fieldset_t; std::map<cbl_field_type_t, fieldset_t> used, freed; public: - cbl_field_t *literal( const char value[], cbl_field_attr_t attr = none_e ); + cbl_field_t *literal( const char value[], uint32_t len, cbl_field_attr_t attr = none_e ); cbl_field_t *acquire( cbl_field_type_t type ); void unacquire( cbl_field_t * field ); };