IBM Support

IZ78417: C COMPILER ISSUE WITH CONST INT ARRAY SIZES

Fixes are available

September 2010 PTF for XL C for AIX, V11.1
September 2010 PTF for XL C/C++ for AIX, V11.1
January 2011 PTF for XL C/C++ for AIX, V11.1
May 2011 PTF for XL C for AIX, V11.1
May 2011 PTF for XL C/C++ for AIX, V11.1
August 2011 PTF for XL C/C++ for AIX, V11.1
November 2011 PTF for XL C/C++ for AIX, V11.1
January 2012 PTF for XL C for AIX, V11.1
January 2012 PTF for XL C/C++ for AIX, V11.1
April 2012 PTF for XL C for AIX, V11.1
April 2012 PTF for XL C/C++ for AIX, V11.1
July 2012 PTF for XL C/C++ for AIX, V11.1
October 2012 PTF for XL C for AIX, V11.1
October 2012 PTF for XL C/C++ for AIX, V11.1
February 2013 PTF for XL C for AIX, V11.1
February 2013 PTF for XL C/C++ for AIX, V11.1
XL C/C++ for AIX Fix Pack 14 (May 2013 PTF) for 11.1
XL C for AIX Fix Pack 14 (May 2013 PTF) for 11.1
XL C/C++ for AIX Fix Pack 15 (August 2013 PTF) for 11.1
XL C for AIX Fix Pack 15 (August 2013 PTF) for 11.1
XL C/C++ for AIX Fix Pack 16 (November 2013 PTF) for 11.1
XL C for AIX Fix Pack 17 (February 2014 PTF) for 11.1
XL C/C++ for AIX Fix Pack 17 (February 2014 PTF) for 11.1
XL C/C++ for AIX Fix Pack 18 (May 2014 PTF) for 11.1
XL C/C++ for AIX Fix Pack 19 (August 2014 PTF) for 11.1
XL C/C++ for AIX Fix Pack 20 (November 2014 PTF) for 11.1
XL C for AIX Fix Pack 21 (April 2015 PTF) for 11.1
XL C/C++ for AIX Fix Pack 21 (April 2015 PTF) for 11.1
XL C/C++ for AIX Fix Pack 22 (September 2015 PTF) for 11.1
XL C for AIX Fix Pack 23 (March 2016 PTF) for 11.1
XL C/C++ for AIX Fix Pack 23 (March 2016 PTF) for 11.1
XL C for AIX Fix Pack 24 (September 2016 PTF) for 11.1
XL C/C++ for AIX Fix Pack 24 (September 2016 PTF) for 11.1
July 2010 PTF for XL C/C++ for AIX, V11.1
July 2010 PTF for XL C for AIX, V11.1
January 2011 PTF for XL C for AIX, V11.1
August 2011 PTF for XL C for AIX, V11.1
November 2011 PTF for XL C for AIX, V11.1
July 2012 PTF for XL C for AIX, V11.1
XL C for AIX Fix Pack 16 (November 2013 PTF) for 11.1
XL C for AIX Fix Pack 18 (May 2014 PTF) for 11.1
XL C for AIX Fix Pack 19 (August 2014 PTF) for 11.1
XL C for AIX Fix Pack 20 (November 2014 PTF) for 11.1
XL C for AIX Fix Pack 22 (September 2015 PTF) for 11.1

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • In c99, when a variable declared as 'const int' is used as size
    in a local array declaration, the size determination and space
    allocation under some conditions is mishandled, and space is not
    allocated.
    
    ===== COMPILE COMMAND:
    xlc test.c
    
    $ cat xlc-bug.c
    #include <stdio.h>
    #include <string.h>
    
    enum { CRDAPPU_CDS_NAMES_MAX_TOKEN_SIZE = 50 };
    typedef char
    crdappu_cds_names_token_t[CRDAPPU_CDS_NAMES_MAX_TOKEN_SIZE];
    
    void write_stuff(crdappu_cds_names_token_t names[]);
    void test_one();
    void test_two();
    
    int main(int argc, char *argv[]){
      if ( argc <= 1) {
        printf("calling test_two\n");
        test_two();
        printf("back from test_two\n");
      }
      else {
        printf("calling test_one\n");
        test_one();
        printf("back test_one\n");
      }
    
      return 0;
    }
    
    
    /*
    ** If we use enum it works
    enum { cdsNamesTokenArrSz = 100 };
    **  With the following, test_two crashes
    **  if it executes before test_one executes
    */
    const int cdsNamesTokenArrSz = 100;
    
    void test_one(){
      char my_array[CRDAPPU_CDS_NAMES_MAX_TOKEN_SIZE];
      char my_array1[CRDAPPU_CDS_NAMES_MAX_TOKEN_SIZE];
      crdappu_cds_names_token_t
    cdsNamesTokenArr[cdsNamesTokenArrSz];
    printf("sizeof my_array = %ld\n", sizeof my_array);
    printf("sizeof my_array1 = %ld\n", sizeof my_array1);
    printf("sizeof cdsNamesTokenArr = %ld\n", sizeof
    cdsNamesTokenArr);
      memset(my_array,' ',sizeof my_array);
      memset(my_array1,' ',sizeof my_array1);
      write_stuff(cdsNamesTokenArr);
    printf("after write_stuff call\n");
      memset(my_array,'1',sizeof my_array);
    printf("after memset to my_array\n");
      memset(my_array1,'1',sizeof my_array1);
    printf("after memset to my_array1\n");
    }
    
    void test_two(){
      char my_array[CRDAPPU_CDS_NAMES_MAX_TOKEN_SIZE];
      char my_array1[CRDAPPU_CDS_NAMES_MAX_TOKEN_SIZE];
      crdappu_cds_names_token_t
    cdsNamesTokenArr[cdsNamesTokenArrSz];
    printf("sizeof my_array = %ld\n", sizeof my_array);
    printf("sizeof my_array1 = %ld\n", sizeof my_array1);
    printf("sizeof cdsNamesTokenArr = %ld\n", sizeof
    cdsNamesTokenArr);
      memset(my_array,' ',sizeof my_array);
      memset(my_array1,' ',sizeof my_array1);
      write_stuff(cdsNamesTokenArr);
    printf("after write_stuff call\n");
      memset(my_array,'1',sizeof my_array);
    printf("after memset to my_array\n");
      memset(my_array1,'1',sizeof my_array1);
    printf("after memset to my_array1\n");
    }
    
    void write_stuff(  crdappu_cds_names_token_t names[]){
      int i,k;
      printf("write_stuff starts\n");
    printf("sizeof names = %ld\n", sizeof names);
    printf("sizeof names[0] = %ld\n", sizeof names[0]);
    printf("sizeof(crdappu_cds_names_token_t) = %ld\n",
    sizeof(crdappu_cds_names_token_t));
      for(i=0;i<100;i++){
        for(k=0;k<sizeof(crdappu_cds_names_token_t);k++){
          names[i][k]='L';
    
        }
    
      }
      printf("write_stuff ends\n");
    }
    $
    
    
    ===== ACTUAL OUTPUT:
    $
    /.../torolab.ibm.com/fs/projects/vabld/run/vacpp/101_com/aix/dai
    ly/latest/bin/xlc xlc-bug.c
    $ ./a.out
    calling test_two
    sizeof my_array = 50
    sizeof my_array1 = 50
    sizeof cdsNamesTokenArr = 0
    write_stuff starts
    sizeof names = 4
    sizeof names[0] = 50
    sizeof(crdappu_cds_names_token_t) = 50
    write_stuff ends
    after write_stuff call
    after memset to my_array
    after memset to my_array1
    Segmentation fault
    $
    
    
    
    ===== EXPECTED OUTPUT:
    $ ./a.out
    calling test_two
    sizeof my_array = 50
    sizeof my_array1 = 50
    sizeof cdsNamesTokenArr = 5000
    write_stuff starts
    sizeof names = 4
    sizeof names[0] = 50
    sizeof(crdappu_cds_names_token_t) = 50
    write_stuff ends
    after write_stuff call
    after memset to my_array
    after memset to my_array1
    back from test_two
    $
    

Local fix

  • Compile the program as C++.
    

Problem summary

  • USERS AFFECTED:
    Any users using variable length arrays at different scopes in
    different orders from sequential order maybe affected by this
    issue.
    
    PROBLEM DESCRIPTION:
    Variable length arrays that are accessed or defined in
    different a order than code order and at different scopes will
    cause invalid runtime values or protection exceptions.
    

Problem conclusion

  • The compiler has been modified so that the variable length
    array size data is scope dependent. Any time a the VLA goes out
    of scope, the size data is cleared and
    so it will be recalculated upon new VLA definition when it
    comes into scope again.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IZ78417

  • Reported component name

    XL C FOR AIX

  • Reported component ID

    5724X1200

  • Reported release

    B10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2010-06-30

  • Closed date

    2010-06-30

  • Last modified date

    2010-06-30

  • APAR is sysrouted FROM one or more of the following:

    IZ69754

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    XL C FOR AIX

  • Fixed component ID

    5724X1200

Applicable component levels

[{"Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSGH2K","label":"XL C for AIX"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"11.1"}]

Document Information

Modified date:
06 October 2021