Fixes are available
APAR status
Closed as program error.
Error description
A segmentation fault may be seen when using the STL <algorithm> sort() function. A C++ standard-conforming change was made to the sort() function in the XL C/C++ for AIX, V12.1.0.3 PTF release for performance reasons. Code not conforming to the standard for sort() usage may encounter issues. Sorting data structures 16 elements in size or smaller is not affected. Per C++03 subclause 25.3 [lib.alg.sorting] paragraphs 3 and 4, the comparison operation should produce !comp(x, x) for all x. In the following test case, the Comp() comparison function uses (ret <= 0) to compare the elements, when a comparison of (ret < 0) should be used to be standard-conforming. This may affect comparison design in some scenarios. === TEST CASE === #include <iostream> #include <cstring> #include <algorithm> using namespace std; struct element { char val1[100]; char val2[100]; }; int compare_element(const struct element *p1, const struct element *p2) { int ret = 0; if( !(ret = strcmp(((struct element *)p1)->val1, ((struct element *)p2)->val1)) && !(ret = strcmp(((struct element *)p1)->val2, ((struct element *)p2)->val2)) ) {} return ret; } struct Comp { bool operator() (const struct element& x, const struct element& y) { int ret = compare_element(&x, &y); if (ret <= 0) return(true); // SHOULD BE (ret < 0) return(false); } }; int main() { static struct element array[] = { {"a","a"}, {"b","b"}, {"c","c"}, {"d","d"}, {"e","e"}, {"f","f"}, {"g","g"}, {"h","h"}, {"i","i"}, {"j","j"}, {"k","k"}, {"l","l"}, {"m","m"}, {"n","n"}, {"o","o"}, {"p","p"}, {"q","q"} }; int nCount = sizeof(array)/sizeof(struct element); cout << "Array Size: " << nCount << endl; struct element *sort_array = (struct element *)malloc(nCount); for(int i = 0; i < nCount; i++) sort_array[i] = array[i]; sort(sort_array, sort_array + nCount, Comp()); return 0; } $ xlC test.cpp $ ./a.out Array Size: 17 Segmentation fault (core dumped) $
Local fix
Modify code to be standard-conforming.
Problem summary
PROBLEM DESCRIPTION: Some non-standard conforming code may encounter issues with the new STL <algorithm> sort() implementation compared to the previous implementation. USERS AFFECTED: Users with non-standard conforming code.
Problem conclusion
For users who are unable to modify their code, the macro __IBMCPP_USE_DEPRECATED_STD_SORT_IMPL has been included to restore the previous STL <algorithm> sort() behaviour. The macro can be defined in-source with a #define before including <algorithm>, or can be included in compile options with -D__IBMCPP_USE_DEPRECATED_STD_SORT_IMPL .
Temporary fix
Comments
APAR Information
APAR number
IV87935
Reported component name
XL C/C++ FOR AI
Reported component ID
5725C7200
Reported release
C10
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt / Xsystem
Submitted date
2016-08-16
Closed date
2016-11-04
Last modified date
2016-11-04
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/C++ FOR AI
Fixed component ID
5725C7200
Applicable component levels
[{"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSGH3R","label":"XL C\/C++ for AIX"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"12.1","Edition":"","Line of Business":{"code":"LOB73","label":"Power TPS"}}]
Document Information
Modified date:
19 August 2024