From d6da95bc4ce45e57ec47016275a2a9a12c8ef0ce Mon Sep 17 00:00:00 2001 From: Robert Dubner Date: Sun, 11 May 2025 13:43:32 -0400 Subject: [PATCH] cobol: Eliminate padding bytes from cbl_declarative_t. [PR119377] By changing the type of a variable in the cbl_declarative_t structure from "bool" to "uint32_t", three uninitialized padding bytes were turned into initialized bytes. This eliminates the valgrind error caused by those uninitialized values. This is an interim fix, which expediently eliminates the valgrind problem. The underlying design flaw, which involves turning a host-side C++ structure into a run-time data block, is slated for complete replacement in the next few weeks. libgcobol/ChangeLog: PR cobol/119377 * common-defs.h: (struct cbl_declaratives_t): Change "bool global" to "uint32_t global". (cherry picked from commit d7d24f9cc55d5cf0a70a984d4e63e8a307710d9e) --- libgcobol/common-defs.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libgcobol/common-defs.h b/libgcobol/common-defs.h index 026f377e74b..e3471c5ccc3 100644 --- a/libgcobol/common-defs.h +++ b/libgcobol/common-defs.h @@ -458,11 +458,25 @@ struct cbl_enabled_exception_t { struct cbl_declarative_t { enum { files_max = 16 }; size_t section; // implies program - bool global; + uint32_t global; // See the note below ec_type_t type; uint32_t nfile, files[files_max]; cbl_file_mode_t mode; +/* The ::global member originally was "bool global". A bool, however, occupies + only one byte of storage. The structure, in turn, is constructed on + four-byte boundaries for members, so there were three padding bytes between + the single byte of global and the ::type member. + + When used to create a "blob", where the structure was treated as a stream + of bytes that were used to create a constructor for an array of bytes, + valgrind noticed that those three padding bytes were not initialized, and + generated the appropriate error message. This made it hard to find other + problems. + + Changing the declaration from "bool" to "uint32_t" seems to have eliminated + the valgrind error without affecting overall performance. */ + cbl_declarative_t( cbl_file_mode_t mode = file_mode_none_e ) : section(0), global(false) , type(ec_none_e) -- 2.47.2