csn1: fix: do not return 0 if no bits left in the buffer
Both csnStreamDecoder() and csnStreamEncoder() shall not return 0
prematurely if no more bits left in the input / output bit-vector.
Returning CSN_ERROR_NEED_MORE_BITS_TO_UNPACK might make more sense,
however we don't know in advance (i.e. without entering the loop)
whether it's an error or not. Some CSN.1 definitions have names
like 'M_*_OR_NULL', what basically means that they're optional
and can be ignored or omitted.
Most of the case statements do check whether the number of remaining
bits is enough to unpack / pack a value, so let's leave it up to
the current CSN_* handler (pointed by pDescr) if no bits left.
Return CSN_ERROR_NEED_MORE_BITS_TO_UNPACK only if the number of
remaining bits is negative as this is an error in any case.
Change-Id: Ie3a15e210624599e39b1e70c8d34efc10c552f6c
diff --git a/src/csn1.c b/src/csn1.c
index 21d3662..6fab9a9 100644
--- a/src/csn1.c
+++ b/src/csn1.c
@@ -153,9 +153,9 @@
guint8 Tag = STANDARD_TAG;
unsigned ib;
- if (remaining_bits_len <= 0)
+ if (remaining_bits_len < 0)
{
- return 0;
+ return ProcessError(readIndex, __func__, CSN_ERROR_NEED_MORE_BITS_TO_UNPACK, pDescr);
}
do
@@ -1463,9 +1463,9 @@
guint8 Tag = STANDARD_TAG;
- if (remaining_bits_len <= 0)
+ if (remaining_bits_len < 0)
{
- return 0;
+ return ProcessError(writeIndex, __func__, CSN_ERROR_NEED_MORE_BITS_TO_UNPACK, pDescr);
}
do