• Catching table overflow

    From Bruce Axtens@21:1/5 to All on Wed Jun 21 01:12:32 2023
    Given this bit of free-form code

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO.

    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 WS-TABLE.
    05 WS-A PIC A(10)
    OCCURS 1 TO 5 TIMES
    DEPENDING ON D1
    INDEXED BY I1.
    01 D1 USAGE BINARY-CHAR UNSIGNED.

    PROCEDURE DIVISION.
    initialize ws-table.
    set i1 to 10.
    move i1 to d1.
    move "thing" to WS-A(i1).
    DISPLAY "ONE-D TABLE : "WS-TABLE.
    STOP RUN.

    This runs without error. Is that what's supposed to happen?

    The GnuCOBOL version is

    cobc (GnuCOBOL) 3.2-dev.0
    Copyright (C) 2022 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart Built Jul 07 2022 09:17:27
    Packaged Jul 07 2022 08:40:44 UTC
    C version (MinGW) "9.2.0"

    -Bruce

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From docdwarf@panix.com@21:1/5 to bruce.axtens@gmail.com on Wed Jun 21 13:18:47 2023
    In article <c34be416-147f-44c4-a219-652768121e79n@googlegroups.com>,
    Bruce Axtens <bruce.axtens@gmail.com> wrote:
    Given this bit of free-form code

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO.

    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 WS-TABLE.
    05 WS-A PIC A(10)
    OCCURS 1 TO 5 TIMES
    DEPENDING ON D1
    INDEXED BY I1.
    01 D1 USAGE BINARY-CHAR UNSIGNED.

    PROCEDURE DIVISION.
    initialize ws-table.
    set i1 to 10.
    move i1 to d1.
    move "thing" to WS-A(i1).
    DISPLAY "ONE-D TABLE : "WS-TABLE.
    STOP RUN.

    This runs without error. Is that what's supposed to happen?

    The table may be full of garbage with a thing in the last entry. Maybe
    post the results you get, now, and what happens if you SET i1 TO 10 before
    you INITIALIZE.

    DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vincent Coen@21:1/5 to Bruce Axtens on Wed Jun 21 19:01:54 2023
    Hello Bruce!

    Wednesday June 21 2023 09:12, Bruce Axtens wrote to All:

    Given this bit of free-form code

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO.

    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 WS-TABLE.
    05 WS-A PIC A(10)
    OCCURS 1 TO 5 TIMES
    DEPENDING ON D1
    INDEXED BY I1.
    01 D1 USAGE BINARY-CHAR UNSIGNED.

    PROCEDURE DIVISION.
    initialize ws-table.
    set i1 to 10.
    move i1 to d1.
    move "thing" to WS-A(i1).
    DISPLAY "ONE-D TABLE : "WS-TABLE.
    STOP RUN.

    This runs without error. Is that what's supposed to happen?

    The GnuCOBOL version is

    cobc (GnuCOBOL) 3.2-dev.0
    Copyright (C) 2022 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> This is free software; see the
    source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by
    Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward
    Hart Built Jul 07 2022 09:17:27 Packaged Jul 07 2022 08:40:44 UTC
    C version (MinGW) "9.2.0"


    Why are you expecting it to produce an error ?

    Although the value used is outside the table range unless you have full diagnostic checks set on compile it would not produce a error condition but doing so produces :

    cobc -x test1.cbl -d -g
    -bash-5.1$ ./test1
    libcob: test1.cbl:15: error: OCCURS DEPENDING ON 'D1' out of bounds: 0
    note: minimum subscript for 'WS-A': 1

    Last statement of "HELLO" was INITIALIZE at line 15 of test1.cbl
    ENTRY HELLO at test1.cbl:15
    Started by ./test1


    I only added 1st line with " >>source free"
    before compiling.

    Without the runtine diags it may well show garbage data but here did not
    as showed :

    -bash-5.1$ cobc -x test1.cbl
    -bash-5.1$ ./test1
    ONE-D TABLE :
    thing

    version used :

    cobc -V
    cobc (GnuCOBOL) 3.2-dev.0
    Built May 30 2023 21:15:38
    Packaged May 30 2023 16:41:34 UTC
    C version "10.4.0"



    Vincent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Axtens@21:1/5 to Vincent Coen on Fri Jun 23 19:29:20 2023
    On Thursday, 22 June 2023 at 2:14:35 am UTC+8, Vincent Coen wrote:
    Why are you expecting it to produce an error ?
    I suppose because many other languages do. I was not aware of the compiler switch and didn't find it after a couple of searches (maybe I didn't search for the right keyword).

    The fact that it doesn't produce an error means I just have to be more careful (or find the relevant switch).

    -Bruce

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From William Fahle@21:1/5 to Bruce Axtens on Thu Jul 6 11:49:30 2023
    On Friday, June 23, 2023 at 9:29:21 PM UTC-5, Bruce Axtens wrote:
    On Thursday, 22 June 2023 at 2:14:35 am UTC+8, Vincent Coen wrote:
    Why are you expecting it to produce an error ?
    I suppose because many other languages do. I was not aware of the compiler switch and didn't find it after a couple of searches (maybe I didn't search for the right keyword).

    The fact that it doesn't produce an error means I just have to be more careful (or find the relevant switch).

    -Bruce
    Up until version 6.1, the IBM COBOL compiler and runtime environment were very sloppy in allowing this sort of thing. Then in 6.1 when they put in checks for such things, all kinds of issues were found in existing code. The migration to 6.1 is quite a
    big deal for many shops.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From docdwarf@panix.com@21:1/5 to billfahle@gmail.com on Thu Jul 6 20:20:12 2023
    In article <e780a289-5a70-4277-9c71-374b6e44ee3an@googlegroups.com>,
    William Fahle <billfahle@gmail.com> wrote:
    On Friday, June 23, 2023 at 9:29:21???PM UTC-5, Bruce Axtens wrote:
    On Thursday, 22 June 2023 at 2:14:35???am UTC+8, Vincent Coen wrote:
    Why are you expecting it to produce an error ?
    I suppose because many other languages do. I was not aware of the
    compiler switch and didn't find it after a couple of searches (maybe I
    didn't search for the right keyword).

    The fact that it doesn't produce an error means I just have to be more >careful (or find the relevant switch).

    -Bruce
    Up until version 6.1, the IBM COBOL compiler and runtime environment
    were very sloppy in allowing this sort of thing. Then in 6.1 when they
    put in checks for such things, all kinds of issues were found in
    existing code. The migration to 6.1 is quite a big deal for many shops.

    Before there was enough core to allow Big Tables in WORKING-STORAGE some
    people would define smaller tables consecutively. It wasn't a difficulty
    as long as the Senior Programmer made sure youngsters with less than five years' experience didn't deal with that code... or until the shop
    installed one of those fancy, new compilers that'd re-arrange storage
    areas.

    Ahhhh, for the Oldene Dayse... did'ja hear that core just fell below the buck-a-byte level?

    DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vincent Coen@21:1/5 to William Fahle on Fri Jul 7 02:16:02 2023
    Hello William!

    Thursday July 06 2023 19:49, William Fahle wrote to All:

    On Friday, June 23, 2023 at 9:29:21 PM UTC-5, Bruce Axtens wrote:
    On Thursday, 22 June 2023 at 2:14:35 am UTC+8, Vincent Coen
    wrote:
    Why are you expecting it to produce an error ?
    I suppose because many other languages do. I was not aware of the
    compiler switch and didn't find it after a couple of searches (maybe
    I didn't search for the right keyword). The fact that it doesn't
    produce an error means I just have to be more careful (or find the
    relevant switch). -Bruce
    Up until version 6.1, the IBM COBOL compiler and runtime environment
    were very sloppy in allowing this sort of thing. Then in 6.1 when they
    put in checks for such things, all kinds of issues were found in
    existing code. The migration to 6.1 is quite a big deal for many
    shops.

    IBM compilers have always had a diag check facility on way or another BUT
    it does depend on what settings are preset when the compiler was built for
    the site. As you no doubt know there are very many that can be so the
    sysprog that sets the new compilers up does so according to a site wide specification created by, hmm well someone any way :)

    I use 3 or 4 of them and they all have different settings pre-configured
    in.

    GnuCobol is not so easy to do and I have requested a more automated way of doing so other than the compiler config files via std=<dialect> etc.

    For more settings run cobc -h

    look for -d (or --debug) -g for enable C compiler debug and stack check

    For tracing the program add -ftraceall when environment var COB_SET_TRACE
    is set to 1 or Y.

    For more details read the Programmers Guide or Reference manuals.


    Vincent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From docdwarf@panix.com@21:1/5 to Vincent Coen on Fri Jul 7 02:29:35 2023
    In article <1688692562@f1.n250.z2.fidonet.ftn>,
    Vincent Coen <VBCoen@gmail.com> wrote:
    Hello William!

    Thursday July 06 2023 19:49, William Fahle wrote to All:

    On Friday, June 23, 2023 at 9:29:21???PM UTC-5, Bruce Axtens wrote:
    On Thursday, 22 June 2023 at 2:14:35???am UTC+8, Vincent Coen
    wrote:
    Why are you expecting it to produce an error ?
    I suppose because many other languages do. I was not aware of the
    compiler switch and didn't find it after a couple of searches (maybe
    I didn't search for the right keyword). The fact that it doesn't
    produce an error means I just have to be more careful (or find the
    relevant switch). -Bruce
    Up until version 6.1, the IBM COBOL compiler and runtime environment
    were very sloppy in allowing this sort of thing. Then in 6.1 when they
    put in checks for such things, all kinds of issues were found in
    existing code. The migration to 6.1 is quite a big deal for many
    shops.

    IBM compilers have always had a diag check facility on way or another BUT
    it does depend on what settings are preset when the compiler was built for >the site.

    SSRANGE would check for SubScriptRANGE. The advantage was that it avoided table overflows, the disadvantage was that it chewed up more resources
    during compiles.

    https://stackoverflow.com/questions/56866908/gnucobol-equivalent-of-nossrange

    DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)