Skip to content

Commit 771346f

Browse files
LEN-5680: Support for 64-bit floats and empty arrays (#8)
1 parent 983c6a5 commit 771346f

2 files changed

Lines changed: 49 additions & 14 deletions

File tree

cborg/CborgHeader.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ class CborgHeader
9292

9393
length = 5;
9494
}
95+
else if (minorType == 27) // 8 bytes
96+
{
97+
if (maxLength < 9)
98+
{
99+
return;
100+
}
101+
102+
value = ((uint64_t) head[1] << 56)
103+
| ((uint64_t) head[2] << 48)
104+
| ((uint64_t) head[3] << 40)
105+
| ((uint64_t) head[4] << 32)
106+
| ((uint64_t) head[5] << 24)
107+
| ((uint64_t) head[6] << 16)
108+
| ((uint64_t) head[7] << 8)
109+
| head[8];
110+
111+
length = 9;
112+
}
95113
else if (minorType == CborBase::TypeIndefinite)
96114
{
97115
value = 31;
@@ -155,6 +173,23 @@ class CborgHeader
155173
| head[length + 4];
156174
length += 5;
157175
}
176+
else if (minorType == 27)
177+
{
178+
if (maxLength < uint32_t(length) + 9)
179+
{
180+
return;
181+
}
182+
183+
value = ((uint64_t) head[length + 1] << 56)
184+
| ((uint64_t) head[length + 2] << 48)
185+
| ((uint64_t) head[length + 3] << 40)
186+
| ((uint64_t) head[length + 4] << 32)
187+
| ((uint64_t) head[length + 5] << 24)
188+
| ((uint64_t) head[length + 6] << 16)
189+
| ((uint64_t) head[length + 7] << 8)
190+
| head[length + 8];
191+
length += 9;
192+
}
158193
else if (minorType == CborBase::TypeIndefinite)
159194
{
160195
value = 31;

source/Cborg.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool Cborg::getCBOR(const uint8_t** pointer, uint32_t* length)
123123
{
124124
list.push_back(units);
125125
units = 2 * head.getValue();
126-
} else if (units == maxOf(units)) {
126+
} else if (units == maxOf(units) && head.getLength() == 0) {
127127
// We're not making progress. We'll just process the current unit
128128
// endlessly. Something is wrong. We need to bail.
129129
return false;
@@ -140,7 +140,7 @@ bool Cborg::getCBOR(const uint8_t** pointer, uint32_t* length)
140140
{
141141
list.push_back(units);
142142
units = head.getValue();
143-
} else if (units == maxOf(units)) {
143+
} else if (units == maxOf(units) && head.getLength() == 0) {
144144
// We're not making progress. We'll just process the current unit
145145
// endlessly. Something is wrong. We need to bail.
146146
return false;
@@ -284,7 +284,7 @@ uint32_t Cborg::getCBORLength()
284284
{
285285
list.push_back(units);
286286
units = 2 * head.getValue();
287-
} else if (units == maxOf(units)) {
287+
} else if (units == maxOf(units) && head.getLength() == 0) {
288288
// We're not making progress. We'll just process the current unit
289289
// endlessly. Something is wrong. We need to bail.
290290
return false;
@@ -301,7 +301,7 @@ uint32_t Cborg::getCBORLength()
301301
{
302302
list.push_back(units);
303303
units = head.getValue();
304-
} else if (units == maxOf(units)) {
304+
} else if (units == maxOf(units) && head.getLength() == 0) {
305305
// We're not making progress. We'll just process the current unit
306306
// endlessly. Something is wrong. We need to bail.
307307
return false;
@@ -428,7 +428,7 @@ Cborg Cborg::find(int32_t key) const
428428
{
429429
list.push_back(units);
430430
units = 2 * head.getValue();
431-
} else if (units == maxOf(units)) {
431+
} else if (units == maxOf(units) && head.getLength() == 0) {
432432
// We're not making progress. We'll just process the current unit
433433
// endlessly. Something is wrong. We need to bail.
434434
return Cborg(NULL, 0);
@@ -447,7 +447,7 @@ Cborg Cborg::find(int32_t key) const
447447
{
448448
list.push_back(units);
449449
units = head.getValue();
450-
} else if (units == maxOf(units)) {
450+
} else if (units == maxOf(units) && head.getLength() == 0) {
451451
// We're not making progress. We'll just process the current unit
452452
// endlessly. Something is wrong. We need to bail.
453453
return Cborg(NULL, 0);
@@ -614,7 +614,7 @@ Cborg Cborg::find(const char* key, std::size_t keyLength) const
614614
{
615615
list.push_back(units);
616616
units = 2 * head.getValue();
617-
} else if (units == maxOf(units)) {
617+
} else if (units == maxOf(units) && head.getLength() == 0) {
618618
// We're not making progress. We'll just process the current unit
619619
// endlessly. Something is wrong. We need to bail.
620620
return Cborg(NULL, 0);
@@ -633,7 +633,7 @@ Cborg Cborg::find(const char* key, std::size_t keyLength) const
633633
{
634634
list.push_back(units);
635635
units = head.getValue();
636-
} else if (units == maxOf(units)) {
636+
} else if (units == maxOf(units) && head.getLength() == 0) {
637637
// We're not making progress. We'll just process the current unit
638638
// endlessly. Something is wrong. We need to bail.
639639
return Cborg(NULL, 0);
@@ -814,7 +814,7 @@ Cborg Cborg::getKey(std::size_t index) const
814814
{
815815
list.push_back(units);
816816
units = 2 * head.getValue();
817-
} else if (units == maxOf(units)) {
817+
} else if (units == maxOf(units) && head.getLength() == 0) {
818818
// We're not making progress. We'll just process the current unit
819819
// endlessly. Something is wrong. We need to bail.
820820
return Cborg(NULL, 0);
@@ -831,7 +831,7 @@ Cborg Cborg::getKey(std::size_t index) const
831831
{
832832
list.push_back(units);
833833
units = head.getValue();
834-
} else if (units == maxOf(units)) {
834+
} else if (units == maxOf(units) && head.getLength() == 0) {
835835
// We're not making progress. We'll just process the current unit
836836
// endlessly. Something is wrong. We need to bail.
837837
return Cborg(NULL, 0);
@@ -962,7 +962,7 @@ Cborg Cborg::at(std::size_t index) const
962962
{
963963
list.push_back(units);
964964
units = 2 * head.getValue();
965-
} else if (units == maxOf(units)) {
965+
} else if (units == maxOf(units) && head.getLength() == 0) {
966966
// We're not making progress. We'll just process the current unit
967967
// endlessly. Something is wrong. We need to bail.
968968
return Cborg(NULL, 0);
@@ -979,7 +979,7 @@ Cborg Cborg::at(std::size_t index) const
979979
{
980980
list.push_back(units);
981981
units = head.getValue();
982-
} else if (units == maxOf(units)) {
982+
} else if (units == maxOf(units) && head.getLength() == 0) {
983983
// We're not making progress. We'll just process the current unit
984984
// endlessly. Something is wrong. We need to bail.
985985
return Cborg(NULL, 0);
@@ -1274,7 +1274,7 @@ void Cborg::print() const
12741274

12751275
list.push_back(units);
12761276
units = 2 * head.getValue();
1277-
} else if (units == maxOf(units)) {
1277+
} else if (units == maxOf(units) && head.getLength() == 0) {
12781278
// We're not making progress. We'll just process the current unit
12791279
// endlessly. Something is wrong. We need to bail.
12801280
return;
@@ -1295,7 +1295,7 @@ void Cborg::print() const
12951295

12961296
list.push_back(units);
12971297
units = head.getValue();
1298-
} else if (units == maxOf(units)) {
1298+
} else if (units == maxOf(units) && head.getLength() == 0) {
12991299
// We're not making progress. We'll just process the current unit
13001300
// endlessly. Something is wrong. We need to bail.
13011301
return;

0 commit comments

Comments
 (0)