A fix is 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 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
**************************************************************** * USERS AFFECTED: Users with non-standard conforming code. * **************************************************************** * PROBLEM DESCRIPTION: Some non-standard conforming code may * * encounter issues with thenew STL * * <algorithm> sort() implementation * * compared to theprevious implementation. * **************************************************************** * RECOMMENDATION: Apply the provided PTF. * * * **************************************************************** .
Problem conclusion
Apply provided fix.
Temporary fix
Comments
APAR Information
APAR number
PI67565
Reported component name
C/C++ FOR MVS
Reported component ID
56551210A
Reported release
7A0
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt / Xsystem
Submitted date
2016-08-16
Closed date
2016-10-31
Last modified date
2016-12-01
APAR is sysrouted FROM one or more of the following:
APAR is sysrouted TO one or more of the following:
UI42168
Modules/Macros
CRTEC128 CRTEC64 CRTE128N CRTHB001 CRTHT001 CRTIB001 CRTIT001
Fix information
Fixed component name
ANSI C++ CLASS
Fixed component ID
568819807
Applicable component levels
R7A0 PSN UI42168
UP16/11/02 P F611
Fix is available
Select the PTF appropriate for your component level. You will be required to sign in. Distribution on physical media is not available in all countries.
[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SG19M","label":"APARs - z\/OS environment"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7A0","Edition":"","Line of Business":{"code":"","label":""}},{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SSTLTF","label":"z\/OS XL C\/C++"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7A0","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]
Document Information
Modified date:
01 December 2016