Closed nberth closed 2 months ago
Are you sure that GCOS checkls on the receiver side? That would be quite strange.
But one thing that could be useful is to only check on arithmetic statements, and never on MOVE
/SET TO
...
Are you sure that GCOS checkls on the receiver side? That would be quite strange.
But one thing that could be useful is to only check on arithmetic statements, and never on
MOVE
/SET TO
...
From our tests we could identify that GCOS allows the aforementioned code pattern (MOVE
from a numeric with invalid data to an alphanumeric item). Still, it errors with INVALID DECIMAL DATA
on similar moves to a numeric item.
My current interpretation is that checks are done on receiver fields, but another reason could be that checks for numeric are performed on MOVE
s only when numeric conversions take place.
yes to the later part, the standard does say that no conversion (only padding/truncation) is done for "same usage", but I'm not 100% sure what that is supposed to mean...
yes to the later part, the standard does say that no conversion (only padding/truncation) is done for "same usage", but I'm not 100% sure what that is supposed to mean...
Further findings on the GCOS side:
MOVE <group-item> TO <PIC 9999V999 item>
) passes properly on GCOS: an "alphanumeric" MOVE
does not incur verification even if the receiver is a numeric item;MOVE
of invalid numeric to an alphanumeric is ok and does not incur any verification on the sender side.Is this okay to be merged @GitMensch ? (this is a critical issue for our customer)
Ops, I may have forgot something - the check is not correct...
Hm, can you please also have a look into the codegen and potentially cob_move? At least "if the target is alphanumeric, the source should be copied over verbatim (memcpy field->data + memcpy COB_ALPHANUMERIC_SPACE), no?
NEWS (+potentially Changedoc adjustment for the last push) would be missing
Hm, can you please also have a look into the codegen and potentially cob_move? At least "if the target is alphanumeric, the source should be copied over verbatim (memcpy field->data + memcpy COB_ALPHANUMERIC_SPACE), no?
Yes I think all these cases are handled in typeck.c:cb_build_move_copy
via typeck.c:cb_build_move_field
. cob_move
seems to do the direct copy as well.
LGTM
Now upstream
This PR alters
MOVE
andSET
statements to check for numerical data in emitter fields only when at least one receiver field is of category numeric. This essentially permits statements likeMOVE SOME-NUMERIC TO SOME-ALPHANUM
to succeed even whenSOME-NUMERIC
holds invalid data.(Old description:)
On some systems (GCOS), checks for non-numeric data in numeric items on MOVE appear to be performed on receiver fields instead of emitters, whereas in GnuCOBOL the checks are always performed on emitters. However, the former behavior seems convenient for encoding "absence" of relevant values (or, in more modern terms, null-ness) by putting
SPACES
in the associated storage area. This notably allows coding patterns where aMOVE SOME-NUMERIC TO SOME-ALPHANUM
is followed by a check for "nullness" withSOME-ALPHANUM IS EQUAL TO SPACES
.Although disabling the (fatal) exception
EC-DATA-INCOMPATIBLE
permits such a coding pattern, it also disables some other checks that are relevant.Another possible workaround is to use the (somewhat obscure)
-fcorrect-numeric
. Yet, this "solution" currently alters emitter fields on MOVES (to putZEROS
instead ofSPACES
), and this is an often undesirable side-effet.This PR currently identifies changes required to implement the check on receiver fiels instead of emitters. Given that this changes the underlying semantics of
MOVE
/SET
(albeit in possibly marginal/rare cases — and this fails a NIST test apparently), one could make this subject to a dialect option.