bergzand / NanoCBOR

CBOR library aimed at heavily constrained devices
Creative Commons Zero v1.0 Universal
48 stars 24 forks source link

decoder: don't decrement remaining in nanocbor_leave_container() #52

Closed benpicco closed 3 years ago

benpicco commented 3 years ago

The remaining value has already been decremented by _enter_container(), no need to decrement it twice.

echo v2NzZXECY2NtZIe/Y2xlZPT/v2VkZWxheRkB9P+/ZGVjaG9pSSdtIGRvbmUh/79jbGVk9f+/ZWRlbGF5GQH0/79jbGVk9P+/ZGVjaG9tTm93IEknbSBkb25lIf9jY2Zn9v8= | base64 -d | bin/fuzztest`

master

Reading 98 bytes from stdin
advancing
parsing cbor
{
  "seq": 2,
  "cmd": [
    {
      "led": False,
    },
    {
      "delay": 500,
    },
    {
      "echo": "I'm done!",
    },
    {
      "led": True,
    },
  ],
  {
    "delay": 500,
  }: {
    "led": False,
  },
  {
    "echo": "Now I'm done!",
  }: "cfg",
  NULL: Unsupported type
Err
},
Done parsing cbor

this patch

Reading 98 bytes from stdin
advancing
parsing cbor
{
  "seq": 2,
  "cmd": [
    {
      "led": False,
    },
    {
      "delay": 500,
    },
    {
      "echo": "I'm done!",
    },
    {
      "led": True,
    },
    {
      "delay": 500,
    },
    {
      "led": False,
    },
    {
      "echo": "Now I'm done!",
    },
  ],
  "cfg": NULL,
},
Done parsing cbor
DanielLockau-MLPA commented 3 years ago

@bergzand I just noticed Ben has published this patch yesterday. Please also consider #53 wrt. the described issue.

benpicco commented 3 years ago

closing this in favor of #54