Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7942 Discussions

struct creation - segmentation fault

Michal_Kvasnicka
Beginner
406 Views
The attached source code produce segmentation fault after "init t2" with current C++ compiler:
Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Version 12.1.1.256 Build 20111011 (Linux xXx 2.6.35-31-generic #62-Ubuntu SMP Tue Nov 8 14:20:11 UTC 2011 x86_64 GNU/Linux)

#include
#include

using std::max;
using std::cout;

struct tstruct
{
double a;
tstruct() : a(0) {};
};

int main(int argc, char *argv[])
{
cout << "init t1\\n";
tstruct *t1 = new tstruct[8];
cout << "init t2\\n";
tstruct *t2 = new tstruct[max(5,8)];
};

$ ./a.out
init t1
init t2
Segmentation fault


Any workaround or recommendation?

Michal
0 Kudos
7 Replies
JenniferJ
Moderator
406 Views
It's a bug.

It can be work-arounded with a local variable for the "max(5,8)" like:

int nbignum=max(5,8);
tstruct *t2 = new tstruct[nbignum];

Thanks for reporting it.
Jennifer
0 Kudos
Michal_Kvasnicka
Beginner
406 Views
I can trace back this bug up to version 12.0.2.

When can I expect the fix?
0 Kudos
Om_S_Intel
Employee
406 Views
Intel compiler development team is working on it. We will post an update here as soon as issue is fixed.

Please use the work arround for time being.
0 Kudos
SergeyKostrov
Valued Contributor II
406 Views
Here are a couple of examples:

struct DATASTRUCT
{
DATASTRUCT() : dA( 0.0L )
{
};
double dA;
};
...
int i;

//1
int iMax1 = max( 2, 4 );
DATASTRUCT **pDs1 = ( DATASTRUCT ** )new DATASTRUCT[ iMax1 ];
for( i = 0; i < iMax1; i++ )
pDs1 = ( DATASTRUCT * )new DATASTRUCT();

//2 - Notes:
// Constructor of the structure isNot called
// CRT-function 'calloc' initializes allocated memory with Zeros
DATASTRUCT *pDs2 = ( DATASTRUCT * )calloc( max( 2, 4 ), sizeof( DATASTRUCT ) );

//3
int iMax3 = max( 2, 4 );
DATASTRUCT **pDs3 = ( DATASTRUCT ** )calloc( iMax3, sizeof( DATASTRUCT * ) );
for( i = 0; i < iMax3; i++ )
pDs3 = ( DATASTRUCT * )calloc( 1, sizeof( DATASTRUCT ) );

0 Kudos
Michal_Kvasnicka
Beginner
406 Views
I just test the latest release Version 12.1.3.293 Build 20120212 and the bug still here!?

What is the reason?
0 Kudos
Georg_Z_Intel
Employee
406 Views
Hello,

our compiler engineers are still working on this (last activity was yesterday). Unfortunately we cannot name you the update release which will contain the fix right now. However, Jennifer will come back to you know once we have a compiler update that's validated.

If the workaround posted above should not be suitable for you we might work on an alternative for the time being.

Best regards,

Georg Zitzlsberger
0 Kudos
JenniferJ
Moderator
406 Views

Hi,
this issue is fixed in update 10 (12.1.4.319, Build 20120410). you can download the Intel C++ Composer XE for Linux update 10 from the Intel Registration Center. The evaluation pkg of Intel C++ Composer XE for Linux is also the latest.

I did the verification on IA32 Linux.

Thanks for reporting it.
Jennifer

0 Kudos
Reply