Skip to content

Commit

Permalink
data.md: handle the case where non-even length byte array is passed in (
Browse files Browse the repository at this point in the history
  • Loading branch information
ehildenb authored and rv-jenkins committed Dec 4, 2019
1 parent 0ef8fd6 commit 4d66123
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions data.md
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,11 @@ These parsers can interperet hex-encoded strings as `Int`s, `ByteArray`s, and `M
// -------------------------------------------------------------
rule #parseByteStack(S) => #parseHexBytes(replaceAll(S, "0x", ""))
rule #parseHexBytes("") => .ByteArray
rule #parseHexBytes(S) => Int2Bytes(1, #parseHexWord(substrString(S, 0, 2)), BE) +Bytes #parseHexBytes(substrString(S, 2, lengthString(S))) requires lengthString(S) >=Int 2
rule #parseHexBytes(S) => #parseHexBytes("0" +String S)
requires notBool lengthString(S) modInt 2 ==Int 0
rule #parseHexBytes(S) => Int2Bytes(1, #parseHexWord(substrString(S, 0, 2)), BE) +Bytes #parseHexBytes(substrString(S, 2, lengthString(S)))
requires lengthString(S) modInt 2 ==Int 0
andBool lengthString(S) >Int 0
rule #parseByteStackRaw(S) => String2Bytes(S)
```
Expand All @@ -826,7 +830,11 @@ These parsers can interperet hex-encoded strings as `Int`s, `ByteArray`s, and `M
// -------------------------------------------------------------
rule #parseByteStack(S) => #parseHexBytes(replaceAll(S, "0x", ""))
rule #parseHexBytes("") => .WordStack
rule #parseHexBytes(S) => #parseHexWord(substrString(S, 0, 2)) : #parseHexBytes(substrString(S, 2, lengthString(S))) requires lengthString(S) >=Int 2
rule #parseHexBytes(S) => #parseHexBytes("0" +String S)
requires notBool lengthString(S) modInt 2 ==Int 0
rule #parseHexBytes(S) => #parseHexWord(substrString(S, 0, 2)) : #parseHexBytes(substrString(S, 2, lengthString(S)))
requires lengthString(S) modInt 2 ==Int 0
andBool lengthString(S) >Int 0
rule #parseByteStackRaw(S) => ordChar(substrString(S, 0, 1)) : #parseByteStackRaw(substrString(S, 1, lengthString(S))) requires lengthString(S) >=Int 1
rule #parseByteStackRaw("") => .WordStack
Expand Down

0 comments on commit 4d66123

Please sign in to comment.