Strange behaviour with NULL types #358
-
|
I'm seeing very odd behaviour in Ada generated code when having type definitions such as:
The generated code for Ada does nothing, null body for the ShutdownEvent_decode_aux procedure. The result, out parameter, is not being set. In this code, part of the decoder of a choice type, the issue occurs: The first print shows that result.Success is True. Since the ShutdownEvent_Decode_aux is null, it should do nothing, and in fact, it's not being called because the compiler optimized it out. I believe the problem might be that out parameters are uninitialized in this case, which means the compiler can zero the record, so a perfectly valid result that was previously set to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Indeed, that's right. The To reproduce I created this grammar: D DEFINITIONS ::=
BEGIN
MyNull ::= NULL
MyChoice ::= CHOICE {
with-null MyNull
}
ENDAnd generated a test case: $ asn1scc -Ada -uper -atc foo.asn
$ makeIt fails at decoding because as you point out, right now the template generates nothing: procedure MyNull_Decode_aux(val: out MyNull; bs : in out adaasn1rtl.encoding.Bitstream; result : OUT adaasn1rtl.ASN1_RESULT)
is
pragma Unreferenced (bs);
pragma Unreferenced (val);
begin
null;
end MyNull_Decode_aux;Instead of result := adaasn1rtl.ASN1_RESULT'(Success => true, ErrorCode => 0);I checked that replacing MyNull with the actual decode_nullType(p) ::= <<
<p> := 0;
result := <rtlModuleName()>.ASN1_RESULT'(Success => true, ErrorCode => 0);
>>So the problem is when using an alias for the @usr3-1415 can you spot the issue in the template generating this code? /*case: A:: = INTEGER (5..5) */
IntNoneRequired_encode(p, sConst, sErrCode) ::= <<
-- No need to encode value since it will always be <sConst> --
null;
>>Thanks |
Beta Was this translation helpful? Give feedback.
Indeed, that's right. The
outparam should always be set (explicitly) to True.To reproduce I created this grammar:
And generated a test case:
It fails at decoding because as you point out, right now the template generates nothing:
Instead of
nullit should generate:result := adaasn1rtl.ASN1_RESULT'(Success => true, ErrorCode => 0);