From d8e6f0f1d0b930ec60ad93fcfb9ccd13cbc87257 Mon Sep 17 00:00:00 2001 From: "James K. Lowden" <jklowden@symas.com> Date: Tue, 17 Dec 2024 14:39:10 -0500 Subject: [PATCH] ensure capcity fits in uint32_t --- gcc/cobol/except.cc | 3 ++- gcc/cobol/parse_ante.h | 9 +-------- gcc/cobol/symbols.h | 7 +++++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gcc/cobol/except.cc b/gcc/cobol/except.cc index d81a7f4796eb..c7f437198f98 100644 --- a/gcc/cobol/except.cc +++ b/gcc/cobol/except.cc @@ -287,7 +287,8 @@ symbol_declaratives_add( size_t program, char achBlob[32]; sprintf(achBlob, "_DECLARATIVE_BLOB%d_", blob_count++); - cbl_field_data_t data = { .memsize = len, .capacity = len, + cbl_field_data_t data = { .memsize = capacity_cast(len), + .capacity = capacity_cast(len), .initial = reinterpret_cast<char*>(blob), .picture = reinterpret_cast<char*>(blob) }; cbl_field_t field = { 0, FldBlob, FldInvalid, constant_e, diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h index f7fce3fe07b8..00b687a22dca 100644 --- a/gcc/cobol/parse_ante.h +++ b/gcc/cobol/parse_ante.h @@ -158,18 +158,11 @@ yyerrorvl( int line, const char *filename, const char fmt[], ... ) { va_end(ap); } -static uint32_t -capacity_cast( size_t size ) { - uint32_t len = static_cast<uint32_t>(size); - assert(len == size); - return len; -} - const char * consistent_encoding_check( const char input[] ) { cbl_field_t faux = { .type = FldAlphanumeric, - .data = { .capacity = capacity_cast(strlen(input)), .initial = input } + .data = { .capacity = capacity_cast(strlen(input)), .initial = input } }; auto s = faux.internalize(); diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h index e316718b8b6a..8cb5c6d4ce19 100644 --- a/gcc/cobol/symbols.h +++ b/gcc/cobol/symbols.h @@ -460,6 +460,13 @@ struct cbl_field_data_t { } }; +static inline uint32_t +capacity_cast( size_t size ) { + uint32_t len = static_cast<uint32_t>(size); + assert(len == size); + return len; +} + struct cbl_occurs_bounds_t { // lower = upper = 0 for a non-table // lower = upper = occurs for a fixed table -- GitLab