Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BLANK WHEN ZERO on signed NUMERIC-EDITED #201

Closed

Conversation

ddeclerck
Copy link
Contributor

On behalf of Chuck.

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this again.

Please recheck the leading sign issue by adjusting the test case.

libcob/move.c Outdated
Comment on lines 1091 to 1106
if (COB_FIELD_HAVE_SIGN (f1) && COB_FIELD_SIGN_SEPARATE (f1)) {
for (; (src < src_end) ; src++) {
if (*src != '0') break;
}
if (src >= src_end) {
memset (dst, (int)' ', (size_t)f2->size);
return;
}
} else {
for (; (src <= src_end) ; src++) {
if (*src != '0') break;
}
if (src > src_end) {
memset (dst, (int)' ', (size_t)f2->size);
return;
}
Copy link
Collaborator

@GitMensch GitMensch Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change it to use something like const unsigned char *check_end = !COB_FIELD_SIGN_SEPARATE (f1) ? src_end : src_end - 1; instead to reduce the duplication.

Also: What about separate and leading sign?
And... where are the overpunched positions checked? As we just had that in the other PR: What about invalid data - should we check with COB_D2I() = 0 instead?

Note: I think there's no use in explicit casting a char to int, is it? The field->size is size_t already, so that should be dropped in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: What about separate and leading sign? And... where are the overpunched positions checked?

There is an invariant here that f1 either has no sign or has a trailing separate sign (as checked by the block between #ifndef NDEBUG block at the top of the function, and also mentionned by Chuck in his message).

As we just had that in the other PR: What about invalid data - should we check with COB_D2I() = 0 instead?

We could add that, though the other PR is about moving from an ALPHANUMERIC source, while optimized_move_display_to_edited only moves from a NUMERIC-DISPLAY source (either a direct one, or a temporary one).

Note: I think there's no use in explicit casting a char to int, is it?

Absolutely, those character literals should already be of type int anyways.

The field->size is size_t already, so that should be dropped in any case.

Done.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an invariant here that f1 either has no sign or has a trailing separate sign (as checked by the block between #ifndef NDEBUG block at the top of the function, and also mentioned by Chuck in his message).

Can you expand that to also the leading separate case (should be simple, and we now even have a testcase ready :-) and to the overpunched sign (a bit more complex)?
Of course we can postpone that to later (either both or one of those)...

As we just had that in the other PR: What about invalid data - should we check with COB_D2I() = 0 instead?

We could add that, though the other PR is about moving from an ALPHANUMERIC source, while optimized_move_display_to_edited only moves from a NUMERIC-DISPLAY source (either a direct one, or a temporary one).

Just checked with MF: After MOVE SPACES TO L(1:3) before the W-X move, by default we get the abort for non-numeric data in numeric displays, when I disable that at run-time, then " 00000" is blanked to space and " 1234" results in " 12,34" while an additional MOVE "A" TO L (8:1) results in

 ===>       0,01<===
 ===>      12,31<===

I guess this is the same for GCOS, in this case we may should at this at the end of that test (and use COB_D2I(c) == 0).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand that to also the leading separate case (should be simple, and we now even have a testcase ready :-) and to the overpunched sign (a bit more complex)? Of course we can postpone that to later (either both or one of those)...

Done for this part.

Just checked with MF: After MOVE SPACES TO L(1:3) before the W-X move, by default we get the abort for non-numeric data in numeric displays, when I disable that at run-time, then " 00000" is blanked to space and " 1234" results in " 12,34" while an additional MOVE "A" TO L (8:1) results in

 ===>       0,01<===
 ===>      12,31<===

Added this to the test case, though the result differs, i.e.:

           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 '<==='.

Yields:

 ===>           <===
 ===>           <===
 ===>     012,34<===
 ===>     012,34<===

Though this is not really related to the "BLANK WHEN ZERO not working anymore" issue.

tests/testsuite.src/run_fundamental.at Outdated Show resolved Hide resolved
Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do question if GCOS would output 012,34...

please see some notes and add a Changelog (and yes, that part is a separate one from Chucks fixing something else - still fine for a single commit as that fixes two errors in the same function that are verified by a single test.

... it seems reasonable to check the CI generated coverage as well, to ensure that at least all parts of this function that is now fixed is actually tested (or at least: executed).

libcob/move.c Outdated Show resolved Hide resolved
tests/testsuite.src/run_fundamental.at Outdated Show resolved Hide resolved
tests/testsuite.src/run_fundamental.at Outdated Show resolved Hide resolved
libcob/move.c Outdated Show resolved Hide resolved
tests/testsuite.src/run_fundamental.at Outdated Show resolved Hide resolved
@ddeclerck
Copy link
Contributor Author

I think I considered all requested changes.

libcob/ChangeLog Show resolved Hide resolved
libcob/move.c Outdated Show resolved Hide resolved
libcob/move.c Outdated Show resolved Hide resolved
libcob/move.c Outdated Show resolved Hide resolved
tests/testsuite.src/run_fundamental.at Outdated Show resolved Hide resolved
@GitMensch
Copy link
Collaborator

Sounds I do wait for the next push, right?

@ddeclerck
Copy link
Contributor Author

ddeclerck commented Dec 13, 2024 via email

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good to me, apart from the Changelog entry we need to fix run_misc.at - the test "Figurative constants to numeric field" (which should get an additional keyword "MOVE") doers not only test what it says, but additional the possible pretty-printing - which it shouldn't.

please change is " NUM9 "." to is " NUM9 (1:) "."

to fix that test

and yes, we have one additional issue which was seen by this: the pretty-printing of USAGE DISPLAY is different in at least those compilers:
acu: no pretty-printing on those at all
mf: all signed fields are printed as if they'd have a "SIGN SEPARATE TRAILING"
gc: full pretty-printing (including decimals, normalization, ...)

but that's something to only create a FR on "provide different pretty-display for USAGE DISPLAY" (and I don't consider that a high priority)

libcob/ChangeLog Show resolved Hide resolved
@ddeclerck
Copy link
Contributor Author

Here we go.

I also sneaked into this the small testsuite adjustment mentionned in your last comment in #203.

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good as-is.

@ddeclerck
Copy link
Contributor Author

ddeclerck commented Dec 17, 2024

Merged in SVN @ 5403.

@GitMensch
Copy link
Collaborator

Happens since this commit - so far only in NC105A

==80021==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5558a5310e65 at pc 0x7fb85f81f06f bp 0x7ffc67696d20 sp 0x7ffc67696d10
READ of size 1 at 0x5558a5310e65 thread T0
    #0 0x7fb85f81f06e in optimized_move_display_to_edited /home/appveyor/projects/gnucobol-3-x/libcob/move.c:1117
    #1 0x7fb85f826e2d in cob_move /home/appveyor/projects/gnucobol-3-x/libcob/move.c:1699
    #2 0x5558a4d0683b in NC105A_ (/home/appveyor/projects/gnucobol-3-x/tests/cobol85/NC/NC105A+0x3cb83b)
    #3 0x5558a4ca87e0 in NC105A (/home/appveyor/projects/gnucobol-3-x/tests/cobol85/NC/NC105A+0x36d7e0)
    #4 0x5558a4ca8797 in main (/home/appveyor/projects/gnucobol-3-x/tests/cobol85/NC/NC105A+0x36d797)
    #5 0x7fb85ec47082 in __libc_start_main ../csu/libc-start.c:308
    #6 0x5558a4ca86ad in _start (/home/appveyor/projects/gnucobol-3-x/tests/cobol85/NC/NC105A+0x36d6ad)

0x5558a5310e65 is located 0 bytes to the right of global variable 'b_111' defined in '/tmp/cob79759_0.c.l.h:101:17' (0x5558a5310e60) of size 5
0x5558a5310e65 is located 59 bytes to the left of global variable 'b_10' defined in '/tmp/cob79759_0.c.l.h:58:17' (0x5558a5310ea0) of size 4
SUMMARY: AddressSanitizer: global-buffer-overflow /home/appveyor/projects/gnucobol-3-x/libcob/move.c:1117 in optimized_move_display_to_edited
Shadow bytes around the buggy address:
  0x0aab94a5a170: 00 00 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9
  0x0aab94a5a180: 05 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
  0x0aab94a5a190: 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 00 00 00 00
  0x0aab94a5a1a0: 00 00 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9
  0x0aab94a5a1b0: 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 07 f9 f9 f9
=>0x0aab94a5a1c0: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9[05]f9 f9 f9
  0x0aab94a5a1d0: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 05 f9 f9 f9
  0x0aab94a5a1e0: f9 f9 f9 f9 05 f9 f9 f9 f9 f9 f9 f9 07 f9 f9 f9
  0x0aab94a5a1f0: f9 f9 f9 f9 00 04 f9 f9 f9 f9 f9 f9 05 f9 f9 f9
  0x0aab94a5a200: f9 f9 f9 f9 07 f9 f9 f9 f9 f9 f9 f9 05 f9 f9 f9
  0x0aab94a5a210: f9 f9 f9 f9 05 f9 f9 f9 f9 f9 f9 f9 02 f9 f9 f9
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==80021==ABORTING

@GitMensch GitMensch reopened this Dec 20, 2024
@GitMensch GitMensch added reopened (merged) already merged, but reopened and removed Merged in SVN labels Dec 20, 2024
Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haven't checked if the error was triggered by that test case (I'd assume so) - but as the test is already run, please add a check for the expected value in Y (`if Y(1:) NOT = ") as well, then commit.

I'd say it is a follow-up of a previous recent change, so no need for a Changelog entry - but please reference it as "follow-up commit to r...." to point to the other one and give a minimal change note in the svn log.

@ddeclerck
Copy link
Contributor Author

haven't checked if the error was triggered by that test case (I'd assume so)

At least it was, locally on my machine - and was fixed with the patch. So, let's be confident ;)

  • but as the test is already run, please add a check for the expected value in Y (`if Y(1:) NOT = ") as well, then commit.

Added.

I'd say it is a follow-up of a previous recent change, so no need for a Changelog entry - but please reference it as "follow-up commit to r...." to point to the other one and give a minimal change note in the svn log.

Alright.

@ddeclerck
Copy link
Contributor Author

Merged in SVN @ 5407.

@GitMensch GitMensch added Merged in SVN and removed reopened (merged) already merged, but reopened labels Dec 20, 2024
@GitMensch GitMensch closed this Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants