Skip to content

Commit 050a002

Browse files
committed
[#493] First draft of documentation for parsing exceptions
1 parent 87f93ab commit 050a002

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

compiler/extensions/cpp/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,59 @@ compatibility version and fires an error when it detects any problem.
1515

1616
> Note: Binary encoding of packed arrays has been changed in version `2.5.0` and thus versions `2.4.x` are
1717
binary incompatible with later versions.
18+
19+
## Functional Safety Features
20+
21+
### C++ runtime library
22+
23+
The following describes features which minimize the risk of Zserio C++ runtime library malfunctioning behavior:
24+
25+
- Supported compilers (minimum versions): gcc 5.4.0, clang 8, MinGW 5.4.0, MSVC 2017
26+
- Warnings are treaded as errors for all supported compilers
27+
- All features are properly tested by unit tests for all supported compilers (>600 tests)
28+
- Implemented automatic check of test coverage threshold for [clang](https://zserio.org/doc/runtime/cpp/coverage/clang/index.html) builds (>98%)
29+
- AddressSanitizer is run with no findings
30+
- UndefinedBehaviourSanitizer is run with no findings
31+
- C++ runtime library sources are checked by static analysis tool clang-tidy version 14 using [this configuration](https://github.com/ndsev/zserio/blob/master/compiler/extensions/cpp/runtime/ClangTidyConfig.txt) with [this report](https://zserio.org/doc/runtime/cpp/clang-tidy/clang-tidy-report.txt)
32+
33+
### C++ Generated Code
34+
35+
The following describes features which minimize the risk of Zserio C++ generated code malfunctioning behavior:
36+
37+
- Supported compilers (minimum versions): gcc 5.4.0, clang 8, MinGW 5.4.0, MSVC 2017
38+
- Warnings are treaded as errors for all supported compilers
39+
- All features are properly tested by unit tests for all supported compilers (>1700 tests)
40+
- Generated C++ sources are checked by static analysis tool clang-tidy version 14 using [this configuration](https://github.com/ndsev/zserio/blob/master/compiler/extensions/cpp/runtime/ClangTidyConfig.txt)
41+
42+
### Exceptions
43+
44+
Zserio C++ runtime library together with the C++ generated code can throw a `zserio::CppRuntimeException` in
45+
some rare circumstances, mainly
46+
47+
- during parsing (reading)
48+
- during writing
49+
- in reflection code
50+
- in type info code
51+
52+
Because there are hundreds possibilities when exception `zserio::CppRuntimeException` can be thrown, the
53+
following section contains only description of exceptions during parsing.
54+
55+
#### Exceptions During Parsing
56+
57+
The following table describes all possibilities when C++ generated code can throw
58+
a `zserio::CppRuntimeException` during parsing of binary data:
59+
60+
| Module | Method | Exception Message | Description |
61+
| ------ | ------ | ----------------- | ----------- |
62+
| `BitStreamReader.cpp` | constructor | "BitStreamReader: Buffer size exceeded limit '[MAX_BUFFER_SIZE]' bytes!" | Throws if provided buffer is bigger that 536870908 bytes (cca 511MB) on 32-bit OS or 2**64/8-4 bytes on 64-bit OS. |
63+
| `BitStreamReader.cpp` | constructor | "BitStreamReader: Wrong buffer bit size ('[BUFFER_SIZE]' < '[SPECIFIED_BYTE_SIZE]')!" | Throws if provided buffer is smaller than specified bit size. This could happen only in case of wrong arguments. |
64+
| `BitStreamReader.cpp` | `throwNumBitsIsNotValid()` | "BitStreamReader: ReadBits #[NUM_BITS] is not valid, reading from stream failed!" | Throws if `readBits()`, `readSignedBits()`, `readBits64()` or `readSignedBits64()` has been called with wrong (too big) `numBits` argument. This could happen only in case of data inconsistency, e.g. if dynamic bit field has length bigger than 32 or 64 bits respectively. |
65+
| `BitStreamReader.cpp` | `throwEof()` | "BitStreamReader: Reached eof(), reading from stream failed!" | Throws if end of underlying buffer has been reached (reading beyond stream). This could happen only in case of data inconsistency, e.g. if array length is defined bigger than is actually stored in the stream). |
66+
| `BitStreamReader.cpp` | `readVarSize()` | "BitStreamReader: Read value '[VARSIZE_VALUE]' is out of range for varsize type!" | Throws if `varsize` value stored in stream is bigger than 2147483647. This could happen only in case of data inconsistency when `varsize` value stored in the stream is wrong. |
67+
| `OptionalHolder.h` | `throwNonPresentException()` | "Trying to access value of non-present optional field!" | Throws if optional value is not present during access. This could happen only in case of data inconsistency when optional field is not present in the stream and there is a reference to it in some expression. |
68+
| Generated Sources | Object read constructor | "Read: Wrong offset for field [COMPOUND_NAME].[FIELD_NAME]: [STREAM_BYTE_POSITION] != [OFFSET_VALUE]!" | Throws in case of wrong offset. This could happen only in case of data inconsistency when offset value stored in the stream is wrong. |
69+
| Generated Sources | Object read constructor | "Read: Constraint violated at [COMPOUND_NAME].[FIELD_NAME]!" | Throws in case of wrong constraint. This could happen only in case of data inconsistency when some constraint is violated. |
70+
| Generated Sources | Object read constructor | "No match in choice [NAME]!" | Throws in case of wrong choice selector. This could happen only in case of data inconsistency when choice selector stored in the stream is wrong. |
71+
| Generated Sources | Object read constructor | "No match in union [NAME]!" | Throws in case of wrong union tag. This could happen only in case of data inconsistency when union tag stored in the stream is wrong. |
72+
| Generated Sources | Bitmask constructor | "Value for bitmask [NAME] out of bounds: [VALUE]!" | Throws if value stored in stream is bigger than bitmask upper bound. This could happen only in case of data inconsistency when bitmask value stored in the stream is wrong. |
73+
| Generated Sources | `valueToEnum` | "Unknown value for enumeration [NAME]: [VALUE]!" | Throws in case of unknown enumeration value. This could happen only in case of data inconsistency when enumeration value stored in the stream is wrong. |

0 commit comments

Comments
 (0)