Fixes are available
October 2010 PTF for XL C/C++ for AIX, V10.1
October 2010 PTF for XL C for AIX, V10.1
May 2012 PTF for XL C/C++ for AIX, V10.1
January 2013 PTF for XL C for AIX, V10.1
January 2013 PTF for XL C/C++ for AIX, V10.1
XL C/C++ for AIX Fix Pack 18 (July 2013 PTF) for 10.1
XL C/C++ for AIX Fix Pack 19 (October 2013 PTF) for 10.1
XL C/C++ for AIX Fix Pack 21 (October 2015 PTF) for 10.1
XL C for AIX Fix Pack 21 (October 2015 PTF) for 10.1
June 2010 PTF for XL C/C++ for AIX, V10.1
June 2010 PTF for XL C for AIX, V10.1
February 2011 PTF for XL C for AIX, V10.1
May 2011 PTF for XL C/C++ for AIX, V10.1
May 2011 PTF for XL C for AIX, V10.1
October 2011 PTF for XL C/C++ for AIX, V10.1
October 2011 PTF for XL C for AIX, V10.1
February 2012 PTF for XL C for AIX, V10.1
February 2012 PTF for XL C/C++ for AIX, V10.1
May 2012 PTF for XL C for AIX, V10.1
September 2012 PTF for XL C for AIX, V10.1
September 2012 PTF for XL C/C++ for AIX, V10.1
XL C for AIX Fix Pack 18 (July 2013 PTF) for 10.1
XL C for AIX Fix Pack 19 (October 2013 PTF) for 10.1
XL C for AIX Fix Pack 20 (October 2014 PTF) for 10.1
XL C/C++ for AIX Fix Pack 20 (October 2014 PTF) for 10.1
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
IZ69754
Reported component name
XL C++ AIX
Reported component ID
5724U8100
Reported release
A10
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt
Submitted date
2010-02-05
Closed date
2010-06-03
Last modified date
2010-06-15
APAR is sysrouted FROM one or more of the following:
APAR is sysrouted TO one or more of the following:
Fix information
Fixed component name
XL C AIX
Fixed component ID
5724U8000
Applicable component levels
Document Information
Modified date:
06 October 2021