[go: up one dir, main page]

Menu

#992 INSPECT: bad COUNT and corrupt REPLACING if specified multiple times

GC 3.x
accepted
INSPECT (9)
5 - default
2025-01-24
2024-09-22
No

The code:

        IDENTIFICATION DIVISION.
        PROGRAM-ID. test2.
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 ITEM PIC X(6) VALUE "BABABC".
        01 COUNT-0 PIC 99 VALUE 0.
        01 COUNT-1 PIC 99 VALUE 0.
        01 COUNT-2 PIC 99 VALUE 0.
        01 COUNT-3 PIC 99 VALUE 0.
        01 COUNT-4 PIC 99 VALUE 0.
        PROCEDURE DIVISION.
        INSPECT ITEM TALLYING
        COUNT-0 FOR ALL "AB", ALL "D"
        COUNT-1 FOR ALL "BC"
        COUNT-2 FOR LEADING "EF"
        COUNT-3 FOR LEADING "B"
        COUNT-4 FOR CHARACTERS;
        INSPECT ITEM REPLACING
        ALL "AB" BY "XY", "D" BY "X"
        ALL "BC" BY "VW"
        LEADING "EF" BY "TU"
        LEADING "B" BY "S"
        FIRST "G" BY "R"
        FIRST "G" BY "P"
        CHARACTERS BY "Z"
        DISPLAY "Counts are: "
                COUNT-0 SPACE 
                COUNT-1 SPACE
                COUNT-2 SPACE
                COUNT-3 SPACE
                COUNT-4
        DISPLAY "Should be:  "
                "02" SPACE 
                "00" SPACE
                "00" SPACE
                "01" SPACE
                "01"
        DISPLAY "Result is " """" ITEM """"
        MOVE "SXYXYZ" TO  ITEM
        DISPLAY "Should be " """" ITEM """"
        GOBACK.
        END PROGRAM test2.

The result after compiling with GC 3.2.1:

Counts are: 02 00 00 01 06
Should be:  02 00 00 01 01
Result is "�XYXY"
Should be "SXYXYZ"

Related

Bugs: #991

Discussion

  • Simon Sobisch

    Simon Sobisch - 2025-01-24
    • labels: --> INSPECT
    • summary: INSPECT example from ISO: bad COUNT-4; corrupt REPLACING --> INSPECT: bad COUNT and corrupt REPLACING if specified multiple times
    • status: open --> accepted
    • assigned_to: Simon Sobisch
    • Group: GC 3.2 --> GC 3.x
     
  • Simon Sobisch

    Simon Sobisch - 2025-01-24

    After going through the ISO rules and adding all examples but the not-yet implemented BACKWARDS phrase (hm, should add them as skipped...), I totally see the bug here.

    both the counting and replacing have the same underlying issue - the internal "already done" is reset within the statement, fixing this showed a missing "+ 1" for marking the length - I'll check those fixes in along with the testsuite adjustments, soon.

     
  • Robert Dubner

    Robert Dubner - 2025-01-24

    Corroboration: I compiled your program with GCOBOL. The results:

    Counts are: 02 00 00 01 01
    Should be:  02 00 00 01 01
    Result is "SXYXYZ"
    Should be "SXYXYZ"
    
     

Log in to post a comment.