aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2020-03-06 08:53:36 +0700
committerfixeria <axilirator@gmail.com>2020-03-11 19:55:55 +0000
commit29aeb901e47b39e8e5629eb5108b3f846393b745 (patch)
tree3a01838d750526156939c5ec0ee189f52ba93b81 /src
parent773cb74ec8d4f0236e59bba0912b60d0f485af9a (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/csn1.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/csn1.c b/src/csn1.c
index 21d3662e..6fab9a95 100644
--- a/src/csn1.c
+++ b/src/csn1.c
@@ -153,9 +153,9 @@ csnStreamDecoder(csnStream_t* ar, const CSN_DESCR* pDescr, struct bitvec *vector
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 @@ gint16 csnStreamEncoder(csnStream_t* ar, const CSN_DESCR* pDescr, struct bitvec
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