diff --git a/libcob/move.c b/libcob/move.c index a185a60f..b2041e1a 100644 --- a/libcob/move.c +++ b/libcob/move.c @@ -1014,12 +1014,13 @@ optimized_move_display_to_edited (cob_field *f1, cob_field *f2) register unsigned char *dst = f2->data; register unsigned char *src = f1->data; const cob_pic_symbol *p; - unsigned char *src_end = src + f1->size - 1; + unsigned char *src_last = src + f1->size - 1; unsigned char *dst_end = f2->data + f2->size; + const int sign = COB_GET_SIGN (f1); unsigned char *prev_float_char = NULL; unsigned char *sign_position = NULL; - int neg = 0; + const int neg = (sign < 0) ? 1 : 0; int is_zero = 1; int suppress_zero = 1; int have_decimal_point = 0; @@ -1037,9 +1038,7 @@ optimized_move_display_to_edited (cob_field *f1, cob_field *f2) if (!(COB_FIELD_TYPE (f2) == COB_TYPE_NUMERIC_EDITED && COB_FIELD_DIGITS (f1) == COB_FIELD_DIGITS (f2) && COB_FIELD_SCALE (f1) == COB_FIELD_SCALE (f2) - && COB_FIELD_HAVE_SIGN (f1) == COB_FIELD_HAVE_SIGN (f2) - && ((COB_FIELD_HAVE_SIGN (f1) && (!COB_FIELD_SIGN_LEADING (f1) && COB_FIELD_SIGN_SEPARATE (f1))) - || !COB_FIELD_HAVE_SIGN (f1)))) { + && COB_FIELD_HAVE_SIGN (f1) == COB_FIELD_HAVE_SIGN (f2))) { cob_runtime_error ("optimized_move_display_to_edited: invalid argument"); } #endif @@ -1084,23 +1083,25 @@ optimized_move_display_to_edited (cob_field *f1, cob_field *f2) } } + if (COB_FIELD_HAVE_SIGN (f1) && COB_FIELD_SIGN_SEPARATE (f1) && COB_FIELD_SIGN_LEADING (f1)) { + src++; + } + /* first check for BLANK WHEN ZERO attribute */ /* Note that if the src field is signed then we */ /* scan for one less byte */ if (COB_FIELD_BLANK_ZERO (f2)) { - const unsigned char *check_end = COB_FIELD_HAVE_SIGN (f1) && COB_FIELD_SIGN_SEPARATE (f1) ? src_end - 1 : src_end; - for (; (src <= check_end) ; src++) { - if (*src != '0') break; + unsigned char *check = src; + unsigned char *check_end = COB_FIELD_HAVE_SIGN (f1) && COB_FIELD_SIGN_SEPARATE (f1) && !COB_FIELD_SIGN_LEADING (f1) ? src_last - 1 : src_last; + for (; (check <= check_end) ; check++) { + if (COB_D2I (*check) != 0) break; } - if (src > check_end) { + if (check > check_end) { memset (dst, ' ', f2->size); + /* Restore the source sign */ + COB_PUT_SIGN (f1, sign); return; } - src = f1->data; - } - - if (COB_FIELD_HAVE_SIGN (f1)) { - neg = (*src_end == '-') ? 1 : 0; } for (p = COB_FIELD_PIC (f2); p->symbol; ++p) { @@ -1304,16 +1305,19 @@ optimized_move_display_to_edited (cob_field *f1, cob_field *f2) } /* LCOV_EXCL_STOP */ } /* END OF SWITCH STATEMENT */ - } /* END OF INNER FOR LOOP */ - } /* END OF OUTER FOR LOOP */ + } /* END OF INNER FOR LOOP */ + } /* END OF OUTER FOR LOOP */ - /************************************************************/ - /* after the edited string is built from the mask */ - /* then the sign mask has to be adjusted according to */ - /* the actual sign of the data. */ - /************************************************************/ + /* Restore the source sign */ + COB_PUT_SIGN (f1, sign); + + /************************************************************/ + /* after the edited string is built from the mask */ + /* then the sign mask has to be adjusted according to */ + /* the actual sign of the data. */ + /************************************************************/ - /* if we have not printed any digits set destination to spaces and return */ + /* if we have not printed any digits set destination to spaces and return */ if (suppress_zero) { if (pad == '*') { @@ -1691,9 +1695,9 @@ cob_move (cob_field *src, cob_field *dst) case COB_TYPE_NUMERIC_EDITED: if (COB_FIELD_DIGITS(src) == COB_FIELD_DIGITS(dst) && COB_FIELD_SCALE(src) == COB_FIELD_SCALE(dst) - && COB_FIELD_HAVE_SIGN(src) == COB_FIELD_HAVE_SIGN(dst) + && COB_FIELD_HAVE_SIGN(src) == COB_FIELD_HAVE_SIGN(dst) /* && ((COB_FIELD_HAVE_SIGN(src) && (!COB_FIELD_SIGN_LEADING(src) && COB_FIELD_SIGN_SEPARATE (src))) - || COB_FIELD_HAVE_SIGN(src) == 0)) { + || COB_FIELD_HAVE_SIGN(src) == 0) */ ) { optimized_move_display_to_edited(src, dst); } else { indirect_move (cob_move_display_to_display, src, dst, diff --git a/tests/testsuite.src/run_fundamental.at b/tests/testsuite.src/run_fundamental.at index fbd4b0f4..5382887d 100644 --- a/tests/testsuite.src/run_fundamental.at +++ b/tests/testsuite.src/run_fundamental.at @@ -7146,10 +7146,28 @@ AT_DATA([prog.cob], [ MOVE -1234 TO W-Z. DISPLAY ' ===>' W-Z '<==='. + DISPLAY "EXTRA FROM SIGN LEADING SEPARATE". + + MOVE 0 TO L. + MOVE SPACES TO L(1:3). + MOVE L TO W-X. + DISPLAY ' ===>' W-X '<==='. + + MOVE "A" TO L(8:1). + DISPLAY ' ===>' W-X '<==='. + + MOVE 1234 TO L. + MOVE SPACES TO L(1:3). + MOVE L TO W-X. + DISPLAY ' ===>' W-X '<==='. + + MOVE "A" TO L(8:1). + DISPLAY ' ===>' W-X '<==='. + STOP RUN. ]) -AT_CHECK([$COMPILE prog.cob], [0], [], [ignore]) +AT_CHECK([$COMPILE -fno-ec=EC-DATA-INCOMPATIBLE prog.cob], [0], [], [ignore]) AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [FROM SIGN LEADING ===> <=== @@ -7203,6 +7221,11 @@ FROM SIGN TRAILING SEPARATE ===>+ 12,34<=== ===>- 12,34<=== ===>- 12,34<=== +EXTRA FROM SIGN LEADING SEPARATE + ===> <=== + ===> <=== + ===> 012,34<=== + ===> 012,34<=== ]) AT_CLEANUP