Skip to content

Commit

Permalink
fix for [r4045] for non-GCC builds
Browse files Browse the repository at this point in the history
cobc/codegen.c (output_display_fields): prevent bad integer promotion in typeck within va_arg by forcing the unsigned long type for the varargs argument

additional:
cobc/typeck.c (cb_build_generic_register): favor memcpy over strncpy
  • Loading branch information
sf-mensch committed Dec 7, 2020
1 parent d2177c2 commit e2d4c26
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
7 changes: 7 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

2020-12-07 Simon Sobisch <[email protected]>

* 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 <[email protected]>

* Makefile.am (cobc_LDADD): fixed ordering, in-tree libraries
Expand Down
8 changes: 5 additions & 3 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -9993,12 +9993,14 @@ output_field_display (struct cb_field *f, size_t offset,
output (", i_%u, ", (cob_u32_t)-field_subscript[i]);
if (cb_flag_odoslide
&& p && p->depending) {
output ("(cob_uli_t)(");
output_size (cb_build_field_reference (p, NULL));
output (")");
} else {
output ("%lu", (cob_uli_t) size_subscript[i]);
output ("%luUL", (cob_uli_t) size_subscript[i]);
}
} else {
output (", %u, 0", (cob_u32_t)field_subscript[i]);
output (", %u, 0UL", (cob_u32_t)field_subscript[i]);
}
/* non-standard level 01 occurs */
if (!p) {
Expand Down Expand Up @@ -10569,8 +10571,8 @@ output_dump_code (struct cb_program *prog, cb_tree parameter_list)
}
if (prog->linkage_storage) {
if (cb_flag_dump & COB_DUMP_LS) {
has_dump = 1;
struct cb_field *f2;
has_dump = 1;
output_newline ();
output_line ("/* Dump LINKAGE SECTION */");
if (prog->num_proc_params) {
Expand Down
7 changes: 4 additions & 3 deletions cobc/typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,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;
Expand Down Expand Up @@ -1231,9 +1230,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 */
Expand All @@ -1255,10 +1255,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_PICTURE (cb_build_picture (temp));
Expand Down
2 changes: 1 addition & 1 deletion libcob/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,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)
Expand Down
12 changes: 8 additions & 4 deletions libcob/termio.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,16 +725,16 @@ dump_field_internal (const int level, const char *name,
cob_field *f_addr, const size_t field_offset,
const unsigned int indexes, va_list ap)
{
FILE *fp = cob_get_dump_file ();

size_t adjust = field_offset;
size_t name_length;
char lvlwrk[LVL_SIZE];
/* fieldname and additional for subscripts: " ()"
+ indexes (max-size 7 + ",") */
char vname[VNAME_MAX + 1];
cob_field f[1];
FILE *fp = cob_get_dump_file ();

cob_u32_t subscript[COB_MAX_SUBSCRIPTS + 1] = { 0 };
cob_u32_t subscript[COB_MAX_SUBSCRIPTS + 1];

/* copy over indexes to local array and calculate size offset */
if (indexes != 0) {
Expand All @@ -755,11 +755,15 @@ dump_field_internal (const int level, const char *name,
adjust += (size_t)size * c_subscript;
subscript[cob_idx - 1] = cob_subscript;
}
while (cob_idx < COB_MAX_SUBSCRIPTS) {
subscript[cob_idx++] = 0;
}
} else {
subscript[0] = 0;
}

/* copy field pointer to allow access to its data pointer and size
and for the actual dump also its attributes */
cob_field f[1];
memcpy (f, f_addr, sizeof (cob_field));

if (!dump_compat) {
Expand Down

0 comments on commit e2d4c26

Please sign in to comment.