NordicSemiconductor / zcbor

Low footprint C/C++ CBOR library and Python tool providing code generation from CDDL descriptions.
Apache License 2.0
105 stars 34 forks source link

Issue approaching 255 in an int #387

Closed jnz86 closed 5 months ago

jnz86 commented 5 months ago

I'm about to get on a plane, so I don't have a ton of time to check this, but I'm doing something roughly like:

my_map_t =  {
    id             :  "i" => uint .size 2,
    ?details       :  "d" => details_t,
}

details_t = { 
    time  : "t" => uint .size 4 .ge 1700000000,
    key   : "k" => key_t,
    array : "a" => bstr .size 12,
}

key_t = (   ( RESERVED_NONE            :   0 ) /
            ( A_BUNCH_OF_VALUES        :  23 ) /
            ( RESERVED_MAX_WORKS       : 254 ) /
            ( RESERVED_MAX_BREAKS      : 255 )
)

I apologize for the terrible report, but RESERVED_MAX_BREAKS when in place, returns the error:

  File "/workspaces/xxx/lib/zcbor/zcbor/zcbor.py", line 1218, in all_children_int_disambiguated
    and max(values) <= INT32_MAX and min(values) >= INT32_MIN
TypeError: '>' not supported between instances of 'str' and 'int'

When I remove 255 or change it to 254, works fine. Looks like maybe an off-by-one error on range checking for a uint8_t?

oyvindronningstad commented 5 months ago

Thanks for the report! Should be fixed in #388.

jnz86 commented 5 months ago

Fast work!

I'll check it out when it's merged. In the meantime I'm sure this can be closed.