313 views
in System Integration by

If I pass an empty string ("") as an argument to a Chora function then in the generated C code it gets translated into 0 rather than a valid pointer.  If my function then passes this "string" to EwStringToAnsi in a native call then I get a segfault (because there is no null-pointer check in EwStringToAnsi, the pointer just gets dereferenced).

Normal case:

T30DayData[i] = LoadGraphData(json_handle, "%a", i);

// gets translated to this generated code which passes a valid pointer:
_this->T30DayData[ i ] = ApplicationDeviceClass_LoadGraphData( _this, json_handle, EwLoadString( &_Const002B ), i );

Broken case:

T30DayData[i] = LoadGraphData(json_handle, "", i);

// gets translated in this, passes a null pointer:
_this->T30DayData[ i ] = ApplicationDeviceClass_LoadGraphData( _this, json_handle, 0, i );

Am I doing something wrong?

I've worked around the problem now, but thought I should post this here as it took me a while to track this down and someone else might find something similar.

1 Answer

0 votes
by

Hi,

as you correctly assumed, there is a bug in the implementation of EwStringToAnsi() function. For optimization purpose, empty strings can be represented in Embedded Wizard by NULL pointers (See Be careful when exchanging strings). The function EwStringToAnsi() however doesn't perform the necessary parameter check. As workaround, add an if-condition before using EwStringToAnsi() function. 

Thank you for this bug-report. We will fix it with the next release.

Best regards

Paul Banach

Embedded Wizard Website | Privacy Policy | Imprint

...