Created On:  2010-04-05

Problem:

Is there a way to verify subscripts and indexes are not making references to an area beyond the definition for a table?
 

Resolution:

We have recently enhanced our support for SSRANGE to now include checking for subscripts, indexes and reference modified items. Our support carries these possible options:
 
 SSRANGE directive possible values are:
 
  1 At run time, subscripts and indexes are checked to ensure they are not referencing an area outside the table, and reference modified items are checked for negative or zero value.
 
  2 At both compile time and run time, subscripts, reference modified items, and indexes are checked to ensure they are not referencing an area outside the table.
 
By using just SSRANGE, we default to use SSRANGE(2) and we will check for items at both compile time and runtime. Be aware that not all items are caught by the compiler. For example, in the following Cobol program both IBM and Micro Focus will flag the usages in paragraphs P3 and P5, but paragraphs P2, P4 and P6 will be passed on and will fail at runtime.
 
       Identification Division.
       Program-Id.  LORINCE.
      *  This program illustrates the flagging done by SSRANGE.
      *  The coding in Paragraphs P3 and P5 will be flagged
      * during the compile, so both the PERFORMs and the entire
      * paragraphs are commented out so one can test this sample
      * and see the runtime error catching in force. By using
      * SSRANGE without any options, Micro Focus defaults to use
      * SSRANGE(2) and will check items for invalid values at
      * both compile time and runtime.
      *  This sample produces equivalent errors with the IBM
      * Enterprise Cobol mainframe compiler and the Micro Focus
      * compilers in Mainframe Express and Net Express.
       Environment Division.
       Data Division.
       Working-Storage Section.
       1   Ctr               Pic 9(3).
       1   WinNotes.
        2   WinNoteLen       Pic S9(3).
        2   WinNote.
         3   WinNoteTbl Occurs 1 to 10 Times
                        Depending On WinNoteLen.
          4   WinChar        Pic X(1).
          4   WinTrakr       Pic 9(3).
       Procedure Division.
       P1.
           Perform P2
      *    Perform P3
           Perform P4
      *    Perform P5
           Perform P6
           Stop Run.
       P2.
      * Reference Modification, Zero length value
           Move Zero to Ctr
           Move 10 to WinNoteLen
           Move '12345' to WinChar (1) (1:Ctr)
           Display ' WinChar (1) = ' WinChar (1).
      *P3.
      * Reference Modification, literal length > target field length
      *    Move '12345' to WinChar (5) (1:25)
      *    Display ' WinChar (5) = ' WinChar (5).
       P4.
      * Reference Modification, identifier length > target field length
           Move 5 to WinNoteLen
           Move '12345' to WinChar (2) (1:WinNoteLen)
           Display ' WinChar (2) = ' WinChar (2).
      *P5.
      * Subscript, literal length > target field length
      *    Move '123' to WinChar (25)
      *    Display ' WinChar (25) = ' WinChar (25).
       P6.
      * Subscript, identifier length > target field length
           Move 15 to WinNoteLen
           Compute WinTrakr (WinNoteLen 1) = 10 WinNoteLen
           Display ' WinTrakr = ' WinTrakr (WinNoteLen 1).
Incident #2357810, 2112089