Skip to content

Commit 412e40f

Browse files
bergzandthiagomacieira
authored andcommitted
pretty: Add ifdefs for float support
Adds ifdefs around the float handling to return an CborErrorUnknownType if compiled without floating point support Signed-off-by: Koen Zandberg <[email protected]>
1 parent f1b3258 commit 412e40f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/cborpretty.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
#include "compilersupport_p.h"
3434
#include "utf8_p.h"
3535

36-
#include <float.h>
3736
#include <inttypes.h>
38-
#include <math.h>
3937
#include <string.h>
4038

39+
#ifndef CBOR_NO_FLOATING_POINT
40+
# include <float.h>
41+
# include <math.h>
42+
#endif
43+
4144
/**
4245
* \defgroup CborPretty Converting CBOR to text
4346
* \brief Group of functions used to convert CBOR to text form.
@@ -452,6 +455,7 @@ static CborError value_to_pretty(CborStreamFunction stream, void *out, CborValue
452455
break;
453456
}
454457

458+
#ifndef CBOR_NO_FLOATING_POINT
455459
case CborDoubleType: {
456460
const char *suffix;
457461
double val;
@@ -465,9 +469,15 @@ static CborError value_to_pretty(CborStreamFunction stream, void *out, CborValue
465469
} else if (false) {
466470
uint16_t f16;
467471
case CborHalfFloatType:
472+
#ifndef CBOR_NO_HALF_FLOAT_TYPE
468473
cbor_value_get_half_float(it, &f16);
469474
val = decode_half(f16);
470475
suffix = flags & CborPrettyNumericEncodingIndicators ? "_1" : "f16";
476+
#else
477+
(void)f16;
478+
err = CborErrorUnsupportedType;
479+
break;
480+
#endif
471481
} else {
472482
cbor_value_get_double(it, &val);
473483
suffix = "";
@@ -490,6 +500,13 @@ static CborError value_to_pretty(CborStreamFunction stream, void *out, CborValue
490500
}
491501
break;
492502
}
503+
#else
504+
case CborDoubleType:
505+
case CborFloatType:
506+
case CborHalfFloatType:
507+
err = CborErrorUnsupportedType;
508+
break;
509+
#endif /* !CBOR_NO_FLOATING_POINT */
493510

494511
case CborInvalidType:
495512
err = stream(out, "invalid");

0 commit comments

Comments
 (0)