netSerial

serializer producing compact bitstreams
git clone https://noulin.net/git/netSerial.git
Log | Files | Refs | README | LICENSE

commit 15c51a5850396a01b5c958b24be9d699234b428e
parent 73a72747443a0da6a7547bac9579fd9c3c1a6b77
Author: Remy Noulin <loader2x@gmail.com>
Date:   Sun, 24 Feb 2019 09:02:23 -0500

fix bug when deserializing empty smallBytes

memcheckNetSerial.c | 11 +++++++++++
netSerial.c         |  8 ++++----
netSerial.c.gcov    | 34 +++++++++++++++++++++++++---------
package.yml         |  2 +-
testNetSerial.c     | 11 +++++++++++
5 files changed, 52 insertions(+), 14 deletions(-)

Diffstat:
MmemcheckNetSerial.c | 11+++++++++++
MnetSerial.c | 8++++----
MnetSerial.c.gcov | 34+++++++++++++++++++++++++---------
Mpackage.yml | 2+-
MtestNetSerial.c | 11+++++++++++
5 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/memcheckNetSerial.c b/memcheckNetSerial.c @@ -40,6 +40,17 @@ void topT(void) { createSmallDict(d); createSmallArray(a); + // empty smallBytes + initiateG(&B); + pushBufferG(B, NULL, 1); + // store garbage data in empty smallBytes + B->B->data = 0; + ck_assert_ptr_eq(getTopTypeG(&ds), NULL); + deserialG(&ds, B); + // nothing should deserialized + ck_assert_ptr_eq(getTopTypeG(&ds), NULL); + terminateG(B); + // undefined undefinedt *oU = allocUndefined(); setTopNFreeG(&n, (baset *)oU); diff --git a/netSerial.c b/netSerial.c @@ -3014,7 +3014,7 @@ internal void arrayNetDeserialLevel0(sArrayt **array, char **data) { internal smallJsont* deserialNetSerialLevel0(smallJsont *self, smallBytest *data) { - if (!data) { + if (!data or !data->B or !data->B->count) { ret self; } @@ -3449,7 +3449,7 @@ internal void arrayNetDeserialLevel1(sArrayt **array, u8 **data, contextt *ctx) internal smallJsont* deserialNetSerialLevel1(smallJsont *self, smallBytest *data) { - if (!data) { + if (!data or !data->B or !data->B->count) { ret self; } @@ -4205,7 +4205,7 @@ internal void uniformArrayNetDeserialLevel2(sArrayt **array, u8 **data, contextt internal smallJsont* deserialNetSerialLevel2(smallJsont *self, smallBytest *data) { - if (!data) { + if (!data or !data->B or !data->B->count) { ret self; } @@ -5240,7 +5240,7 @@ internal void uniformArrayNetDeserial(sArrayt **array, u8 **data, contextt *ctx, internal smallJsont* deserialNetSerial(smallJsont *self, smallBytest *data) { - if (!data) { + if (!data or !data->B or !data->B->count) { ret self; } diff --git a/netSerial.c.gcov b/netSerial.c.gcov @@ -4441,9 +4441,13 @@ call 0 never executed function deserialNetSerialLevel0 called 0 returned 0% blocks executed 0% #####: 3015:internal smallJsont* deserialNetSerialLevel0(smallJsont *self, smallBytest *data) { -: 3016: - #####: 3017: if (!data) { + #####: 3017: if (!data or !data->B or !data->B->count) { branch 0 never executed branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed #####: 3018: ret self; -: 3019: } -: 3020: @@ -5071,9 +5075,13 @@ call 0 never executed function deserialNetSerialLevel1 called 0 returned 0% blocks executed 0% #####: 3450:internal smallJsont* deserialNetSerialLevel1(smallJsont *self, smallBytest *data) { -: 3451: - #####: 3452: if (!data) { + #####: 3452: if (!data or !data->B or !data->B->count) { branch 0 never executed branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed #####: 3453: ret self; -: 3454: } -: 3455: @@ -6192,9 +6200,13 @@ call 0 never executed function deserialNetSerialLevel2 called 0 returned 0% blocks executed 0% #####: 4206:internal smallJsont* deserialNetSerialLevel2(smallJsont *self, smallBytest *data) { -: 4207: - #####: 4208: if (!data) { + #####: 4208: if (!data or !data->B or !data->B->count) { branch 0 never executed branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed #####: 4209: ret self; -: 4210: } -: 4211: @@ -7757,13 +7769,17 @@ call 0 returned 100% -: 5238: } -: 5239:} -: 5240: -function deserialNetSerial called 77 returned 100% blocks executed 78% - 77: 5241:internal smallJsont* deserialNetSerial(smallJsont *self, smallBytest *data) { +function deserialNetSerial called 78 returned 100% blocks executed 91% + 78: 5241:internal smallJsont* deserialNetSerial(smallJsont *self, smallBytest *data) { -: 5242: - 77: 5243: if (!data) { -branch 0 taken 0% (fallthrough) -branch 1 taken 100% - #####: 5244: ret self; + 78: 5243: if (!data or !data->B or !data->B->count) { +branch 0 taken 100% (fallthrough) +branch 1 taken 0% +branch 2 taken 100% (fallthrough) +branch 3 taken 0% +branch 4 taken 1% (fallthrough) +branch 5 taken 99% + 1: 5244: ret self; -: 5245: } -: 5246: 77: 5247: smallt *o = netDeserial(data->B); diff --git a/package.yml b/package.yml @@ -1,6 +1,6 @@ --- name: netSerial - version: 0.0.3 + version: 0.0.4 description: "network serializer with binary format more compact than the default serializer in smallJson" bin: ./netSerial.c #cflags: -DA -ggdb -std=gnu11 -fPIC -pipe diff --git a/testNetSerial.c b/testNetSerial.c @@ -36,6 +36,17 @@ START_TEST(topT) createSmallDict(d); createSmallArray(a); + // empty smallBytes + initiateG(&B); + pushBufferG(B, NULL, 1); + // store garbage data in empty smallBytes + B->B->data = 0; + ck_assert_ptr_eq(getTopTypeG(&ds), NULL); + deserialG(&ds, B); + // nothing should deserialized + ck_assert_ptr_eq(getTopTypeG(&ds), NULL); + terminateG(B); + // undefined undefinedt *oU = allocUndefined(); setTopNFreeG(&n, (baset *)oU);