From 6d60308c24cdb02724a717449418a52a2fb143bf Mon Sep 17 00:00:00 2001 From: David Declerck Date: Wed, 12 Jun 2024 17:28:27 +0200 Subject: [PATCH] Merge SVN 4057 --- cobc/ChangeLog | 7 +++++++ cobc/typeck.c | 7 ++++--- libcob/common.c | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 0324cb2ed..49c9ed5b1 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -956,6 +956,13 @@ * codegen.c (output_dump_code): emit code for BASED/LINKAGE fields to catch SIGSEGV/SIGBUS/SIGFPE and then skip the dump of that record +2020-12-07 Simon Sobisch + + * codegen.c (output_display_fields): prevent bad integer promotion in + libcob (typeck within va_arg) by forcing the unsigned long type for + the varargs argument + * typeck.c (cb_build_generic_register): favor memcpy over strncpy + 2020-12-06 Simon Sobisch * Makefile.am (cobc_LDADD): fixed ordering, in-tree libraries diff --git a/cobc/typeck.c b/cobc/typeck.c index efe292610..5deba614f 100644 --- a/cobc/typeck.c +++ b/cobc/typeck.c @@ -1658,7 +1658,6 @@ cb_build_generic_register (const char *name, const char *external_definition, { cb_tree field_tree; char definition[COB_MINI_BUFF]; - char temp[COB_MINI_BUFF] = { 0 }; char *p, *r; struct cb_field *field; enum cb_usage usage; @@ -1707,9 +1706,10 @@ cb_build_generic_register (const char *name, const char *external_definition, if (strncmp (p, "DISPLAY", (size_t)7) == 0) { memset (p, ' ', 7); } else { + char temp[COB_MINI_BUFF]; r = p; while (*r != 0 && *r != ' ') r++; - strncpy (temp, p, r - p); + memcpy (temp, p, r - p); temp [r - p] = 0; memset (p, ' ', r - p); COB_UNUSED (temp); /* FIXME: parse actual USAGE from temp */ @@ -1731,10 +1731,11 @@ cb_build_generic_register (const char *name, const char *external_definition, } } if (p) { + char temp[COB_MINI_BUFF]; while (*p == ' ') p++; r = p; while (*r != 0 && *r != ' ') r++; - strncpy (temp, p, r - p); + memcpy (temp, p, r - p); temp [r - p] = 0; memset (p, ' ', r - p); picture = cb_build_picture (temp); diff --git a/libcob/common.c b/libcob/common.c index a6463ab4d..8d35ff210 100644 --- a/libcob/common.c +++ b/libcob/common.c @@ -571,7 +571,7 @@ static int set_config_val (char *value, int pos); static char *get_config_val (char *value, int pos, char *orgvalue); static void cob_dump_module (char *reason); -static char abort_reason[COB_MINI_BUFF] = { 0 }; +static char abort_reason[COB_MINI_BUFF] = ""; static unsigned int dump_trace_started; /* ensures that we dump/stacktrace only once */ #define DUMP_TRACE_DONE_DUMP (1U << 0) #define DUMP_TRACE_DONE_TRACE (1U << 1)