SegFault - Node Context handling

53 views
Skip to first unread message

Joanna J.

unread,
Aug 27, 2021, 6:32:30 AM8/27/21
to open62541


 Dear community,

I got a question regarding the nodecontext handling of specific nodes. I set a node context for a node and compiled it with -O1 (also -O3) (Release) which ends up in a Segmentation Fault. In Debug mode everything works fine.

Code example:


typedef struct{
    UA_UInt16 *array_first;
    UA_UInt16 *array_second;
} array_struct;

static UA_StatusCode addNodeContextto_node(UA_Server *server){
array_struct* array_sruct_example = (array_struct *) malloc(sizeof(array_struct));
 array_sruct_example->array_first = (UA_UInt16*)UA_Array_new(2, &UA_TYPES[UA_TYPES_UINT16]);
 array_sruct_example->array_second = (UA_UInt16*)UA_Array_new(1, &UA_TYPES[UA_TYPES_UINT16]);
 
 array_sruct_example->array_first[0] = 2;
 array_sruct_example->array_first[1] = 3;
 
 array_sruct_example->array_second[0] = 4;
 
 UA_Server_setNodeContext(server, UA_NODEID_NUMERIC(2, NODE_ID_EXAMPLE), array_sruct_example);
 }


Actually everything should work fine.. but somehow memory gets corrupted. Do you have an idea or do I use the nodecontext in a wrong way?

Cheers,
Joanna

Joanna J.

unread,
Aug 29, 2021, 5:14:35 AM8/29/21
to open62541
Ok,

a return value

return UA_STATUSCODE_GOOD; 

in the last function fixed the issue. Which is quite amazing. Does anyone has a clue why skipping the return value causes a segmentation fault?

Cheers,
Joanna

Julius Pfrommer

unread,
Aug 30, 2021, 5:19:38 AM8/30/21
to open62541
Hmm. Most compilers woulnd't even allow the function to compile without a return value.
Are you outside the typical GCC/Clang/MSVC range of compilers?

Regards

Joanna J.

unread,
Aug 30, 2021, 7:08:07 AM8/30/21
to open62541
Hi Julius,

I know there is a warning which I have not noticed ... but actually the compiler creates a default value and as long as you do not use the "return" value the behaviour should not be undefined.
I do not say that it is ok that you have no return value, it is definitely bad practice. But I cannot explain to myself why a segmentation fault happens though the compiler can actally deal with it.

Is it may be an issue that I compile with g++ (9.3.0) and use an

extern "C" void  addNodeContextto_node (UA_Server *server);

?

Cheers,
Joanna

Joanna J.

unread,
Aug 30, 2021, 7:09:10 AM8/30/21
to open62541
instead of void it is UA_StatusCode ..

Behrens Uwe

unread,
Aug 30, 2021, 7:58:57 AM8/30/21
to Joanna J., open62541

There is definitely something going on corrupting your name mangling scheme and your function return value stack. I recommend you (a) delete all your object code and rebuild the entire project from scratch and (b) do this with the whole set of compiler warnings switched on (in gcc terminology: '-Wall -Wpedantic') and then check the entire set of reported warnigs and errors. I’m quite sure you will find some problems with function declarations vs. function definitions and/or functions having been declared 'extern "C"', but not having been defined as such. Function overloading can be a nuisance in C++, but need not be, when used properly.

 

Mit freundlichen Grüßen / best regards

 

Uwe Behrens

Forschung & Entwicklung / Research & Development

Technologie / Technology

 

cid:image001.png@01D6B76E.A5586E90

 

MARTIN GmbH für Umwelt- und Energietechnik  l   Leopoldstraße 246 - 80807 München  
Phone: +49 (0)89-35617-374

uwe.b...@martingmbh.dewww.martingmbh.de

--
You received this message because you are subscribed to the Google Groups "open62541" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open62541+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/open62541/a7a379f9-2565-4e5d-8977-4550c99f5a5fn%40googlegroups.com.


MARTIN GmbH für Umwelt- und Energietechnik - Leopoldstraße 246 - D-80807 München
Geschäftsführer: Dipl.-Ing. Ulrich Martin - Dipl.-Volksw. Hans Peter Holl - Dr. Fritz Brühl
Registergericht: Amtsgericht München, HRB: 69889 UST-ID: DE 129409300 Steuernr. 143/159/80446
This email including its attachments may contain confidential and/or privileged information and is intended solely for the person(s) or entity to which it is addressed. Any review, disclosure, dissemination or any use of the information contained by persons or entities other than the intended recipient is strictly prohibited.
Der Schutz Ihrer personenbezogenen Daten ist uns wichtig. Umfassende Informationen zur Verarbeitung Ihrer personenbezogenen Daten finden Sie auf unserer Webseite unter Datenschutz.
The protection of your personal data is important to us. Comprehensive information on the processing of your personal data can be found on our website under Data Privacy Policy.

Reply all
Reply to author
Forward
0 new messages