Skip to content

Commit

Permalink
fix corruption of MOVE DISP TO PACKED, bug introduced with [r5128]
Browse files Browse the repository at this point in the history
libcob/move.c (cob_move_display_to_packed): fix data corruption caused by packing one extra digit from the input display field
  • Loading branch information
chaat committed Jul 28, 2023
1 parent 74d62e2 commit 6f07531
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

2023-07-27 Chuck Haatvedt <[email protected]>

* move.c (cob_move_display_to_packed): fix data corruption caused
by packing one extra digit from the input display field

2023-07-24 Simon Sobisch <[email protected]>

* fileio.c: only check -1 as invalid fd; return fileio status for
Expand Down
4 changes: 4 additions & 0 deletions libcob/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ cob_move_display_to_packed (cob_field *f1, cob_field *f2)
p += 2;
}
}
/* clean bottom nibble if we packed one extra digit past the end of the input */
if (p > p_end) {
*(q - 1) &= 0xf0;
}
}

COB_PUT_SIGN_ADJUSTED (f1, sign);
Expand Down
35 changes: 28 additions & 7 deletions tests/testsuite.src/data_packed.at
Original file line number Diff line number Diff line change
Expand Up @@ -830,13 +830,34 @@ AT_DATA([prog.cob], [
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 D-S99V99 PIC S99V99 DISPLAY VALUE 1.23.
01 D-N99V99 PIC S99V99 DISPLAY VALUE -1.32.
01 D-9V99 PIC 9V99 DISPLAY VALUE 1.1.
01 D-S99 PIC S99 DISPLAY VALUE 12.
01 D-99 PIC 99 DISPLAY VALUE 2.
01 D-P99 PIC P99 DISPLAY VALUE 0.02.
01 D-9PP PIC 9PP DISPLAY VALUE 200.
01 FILLER.
05 FILLER PIC XX VALUE '12'.
05 D-S99V99 PIC S99V99 DISPLAY VALUE 1.23.
05 FILLER PIC XX VALUE '34'.
01 FILLER.
05 FILLER PIC XX VALUE '12'.
05 D-N99V99 PIC S99V99 DISPLAY VALUE -1.32.
05 FILLER PIC XX VALUE '34'.
01 FILLER.
05 FILLER PIC XX VALUE '12'.
05 D-9V99 PIC 9V99 DISPLAY VALUE 1.1.
05 FILLER PIC XX VALUE '34'.
01 FILLER.
05 FILLER PIC XX VALUE '12'.
05 D-S99 PIC S99 DISPLAY VALUE 12.
05 FILLER PIC XX VALUE '34'.
01 FILLER.
05 FILLER PIC XX VALUE '12'.
05 D-99 PIC 99 DISPLAY VALUE 2.
05 FILLER PIC XX VALUE '34'.
01 FILLER.
05 FILLER PIC XX VALUE '12'.
05 D-P99 PIC P99 DISPLAY VALUE 0.02.
05 FILLER PIC XX VALUE '34'.
01 FILLER.
05 FILLER PIC XX VALUE '12'.
05 D-9PP PIC 9PP DISPLAY VALUE 200.
05 FILLER PIC XX VALUE '34'.
01 P-S99V99 PIC S99V99 PACKED-DECIMAL.
01 P-99V9 PIC 99V9 PACKED-DECIMAL.
01 P-S999 PIC S999 PACKED-DECIMAL.
Expand Down

0 comments on commit 6f07531

Please sign in to comment.