Skip to content

Commit

Permalink
Fix overlapping move between Alphanum and Display
Browse files Browse the repository at this point in the history
  • Loading branch information
lefessan committed Oct 11, 2024
1 parent 02341d1 commit 34621d7
Show file tree
Hide file tree
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
Expand Up @@ -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 = 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 */
Expand Down Expand Up @@ -359,11 +366,14 @@ cob_move_alphanum_to_display (cob_field *f1, cob_field *f2)
}

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

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

static void
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite.src/run_file.at
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 34621d7

Please sign in to comment.