Skip to main content
10-Marble
June 8, 2023
Solved

User Defined Struct Crashing Creo to Fatally Crash

Hello community,

 

I am working on creo 9.0.2.0

 

I am defining my own struct as this:

typedef struct ParmNote {

struct ParmNote *Next;
struct ParmNote *Last;
char Note[120];
wchar_t wcNote[120];

}NOTE_PARAM;

 

In a later function I have:

 

{

NOTE_PARAM *Current , *Next , *Last , *First;


First = (NOTE_PARAM *)(mParm->PString);
Last = First->Last;
Current = Last;
Next = (NOTE_PARAM *)malloc(sizeof (NOTE_PARAM));
Current->Next = Next;
First->Last = Next;
Current = Next;
Current->Next = NULL;
}

 

When it reaches the underlined line of code "Current->Next = Next;", creo fatally crashes. I do not understand why this is causing Creo to crash, as this exact logic worked in Creo 5.

 

Any and all help would be appreciated.

 

Thank you,

Mark Hardebeck

FV_01
FV_01Answer
June 9, 2023

if you would rewrite code to eliminate unnecessary variable assignments and replace malloc with calloc(...) to have allocated memory initialized:

 

{
 NOTE_PARAM *first = (NOTE_PARAM *)(mParm->PString);
 //assert(NULL == first->Last);
 if( NULL != first && NULL == first->Last){
 first->Last = (NOTE_PARAM *)calloc(1, sizeof (NOTE_PARAM));
 }
 //assert(NULL != first->Last);
 //assert(NULL == first->Last->Next);
}

 

the reason for crash would be easier to detect.

HIH

6 replies

KenFarley
21-Topaz II
June 9, 2023

Are you sure that the data contained in mParm->PString is compatible with NOTE_PARAM?

Have you verified that the pointer First->Last is indeed valid, not NULL, and not random data created when memory was allocated? It's a good rule to always initialize pointers to NULL or the equivalent when they are created, and verification before use is imperative.

If First->Last is not a valid pointer to a properly allocated NOTE_PARAM structure, that would wreak the havoc you are seeing.

Translate
10-Marble
June 9, 2023

Yes, I have verified that mParm->PString is compatible and that First->Last is not NULL.

Translate
FV_01
FV_0117-PeridotAnswer
June 9, 2023

if you would rewrite code to eliminate unnecessary variable assignments and replace malloc with calloc(...) to have allocated memory initialized:

 

{
 NOTE_PARAM *first = (NOTE_PARAM *)(mParm->PString);
 //assert(NULL == first->Last);
 if( NULL != first && NULL == first->Last){
 first->Last = (NOTE_PARAM *)calloc(1, sizeof (NOTE_PARAM));
 }
 //assert(NULL != first->Last);
 //assert(NULL == first->Last->Next);
}

 

the reason for crash would be easier to detect.

HIH

Translate