Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix overlapping move between Alphanum and Display
Browse files Browse the repository at this point in the history
lefessan committed Oct 11, 2024
1 parent 02341d1 commit 5a63526
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions libcob/move.c
Original file line number Diff line number Diff line change
@@ -299,8 +299,15 @@ cob_move_alphanum_to_display (cob_field *f1, cob_field *f2)
int sign;
int count;
int size;
unsigned char *tmp_src_data = NULL;

/* Initialize */
if ( (s1 >= s2 && s1 < e2) || (s2 >= s1 && s2 < e1) ){
tmp_src_data = cob_malloc (f1->size);
memcpy (tmp_src_data, s1, f1->size);
s1 = tmp_src_data;
e1 = s1 + f1->size;
}
memset (f2->data, '0', f2->size);

/* Skip white spaces */
@@ -359,11 +366,14 @@ cob_move_alphanum_to_display (cob_field *f1, cob_field *f2)
}

COB_PUT_SIGN (f2, sign);
if (tmp_src_data) cob_free (tmp_src_data);
return;

error:
memset (f2->data, '0', f2->size);
COB_PUT_SIGN (f2, 0);
if (tmp_src_data) cob_free (tmp_src_data);
return;
}

static void
2 changes: 1 addition & 1 deletion tests/testsuite.src/run_file.at
Original file line number Diff line number Diff line change
@@ -14685,7 +14685,7 @@ AT_CHECK([$COMPILE prog.cob -o prog], [0], [],
[prog.cob:16: warning: overlapping MOVE may produce unpredictable results
])

AT_CHECK([./prog], [0], [00000
AT_CHECK([./prog], [0], [01234
])

AT_CLEANUP

0 comments on commit 5a63526

Please sign in to comment.