Convert C++/C99 style comments to C89
I'm only doing this once and I'll probably regress later.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
diff --git a/src/cbor.h b/src/cbor.h
index 7f11475..2cb2d35 100644
--- a/src/cbor.h
+++ b/src/cbor.h
@@ -455,5 +455,5 @@
}
#endif
-#endif // CBOR_H
+#endif /* CBOR_H */
diff --git a/src/cborconstants_p.h b/src/cborconstants_p.h
index e8ab8b6..d5808c3 100644
--- a/src/cborconstants_p.h
+++ b/src/cborconstants_p.h
@@ -36,7 +36,7 @@
enum {
SmallValueBitLength = 5U,
- SmallValueMask = (1U << SmallValueBitLength) - 1, // 31
+ SmallValueMask = (1U << SmallValueBitLength) - 1, /* 31 */
Value8Bit = 24U,
Value16Bit = 25U,
Value32Bit = 26U,
@@ -49,5 +49,4 @@
BreakByte = (unsigned)Break | (SimpleTypesType << MajorTypeShift)
};
-#endif // CBORCONSTANTS_P_H
-
+#endif /* CBORCONSTANTS_P_H */
diff --git a/src/cborencoder.c b/src/cborencoder.c
index 11d4e85..8ef4a43 100644
--- a/src/cborencoder.c
+++ b/src/cborencoder.c
@@ -47,11 +47,11 @@
memcpy(where, &v, sizeof(v));
}
-// Note: Since this is currently only used in situations where OOM is the only
-// valid error, we KNOW this to be true. Thus, this function now returns just 'true',
-// but if in the future, any function starts returning a non-OOM error, this will need
-// to be changed to the test. At the moment, this is done to prevent more branches
-// being created in the tinycbor output
+/* Note: Since this is currently only used in situations where OOM is the only
+ * valid error, we KNOW this to be true. Thus, this function now returns just 'true',
+ * but if in the future, any function starts returning a non-OOM error, this will need
+ * to be changed to the test. At the moment, this is done to prevent more branches
+ * being created in the tinycbor output */
static inline bool isOomError(CborError err)
{
(void) err;
@@ -119,7 +119,7 @@
uint64_t buf[2];
uint8_t *const bufend = (uint8_t *)buf + sizeof(buf);
uint8_t *bufstart = bufend - 1;
- put64(buf + 1, ui); // we probably have a bunch of zeros in the beginning
+ put64(buf + 1, ui); /* we probably have a bunch of zeros in the beginning */
if (ui < Value8Bit) {
*bufstart += shiftedMajorType;
@@ -157,17 +157,17 @@
CborError cbor_encode_int(CborEncoder *encoder, int64_t value)
{
- // adapted from code in RFC 7049 appendix C (pseudocode)
- uint64_t ui = value >> 63; // extend sign to whole length
- uint8_t majorType = ui & 0x20; // extract major type
- ui ^= value; // complement negatives
+ /* adapted from code in RFC 7049 appendix C (pseudocode) */
+ uint64_t ui = value >> 63; /* extend sign to whole length */
+ uint8_t majorType = ui & 0x20; /* extract major type */
+ ui ^= value; /* complement negatives */
return encode_number(encoder, ui, majorType);
}
CborError cbor_encode_simple_value(CborEncoder *encoder, uint8_t value)
{
#ifndef CBOR_ENCODER_NO_CHECK_USER
- // check if this is a valid simple type
+ /* check if this is a valid simple type */
if (value >= HalfPrecisionFloat && value <= Break)
return CborErrorIllegalSimpleType;
#endif
@@ -193,7 +193,7 @@
CborError cbor_encode_tag(CborEncoder *encoder, CborTag tag)
{
- // tags don't count towards the number of elements in an array or map
+ /* tags don't count towards the number of elements in an array or map */
return encode_number_no_update(encoder, tag, TagType << MajorTypeShift);
}
diff --git a/src/cborencoder_close_container_checked.c b/src/cborencoder_close_container_checked.c
index aad2ebf..a674823 100644
--- a/src/cborencoder_close_container_checked.c
+++ b/src/cborencoder_close_container_checked.c
@@ -39,7 +39,7 @@
if (containerEncoder->flags & CborIteratorFlag_UnknownLength || encoder->end == NULL)
return err;
- // check what the original length was
+ /* check what the original length was */
uint64_t actually_added;
err = extract_number(&ptr, encoder->ptr, &actually_added);
if (err)
diff --git a/src/cborjson.h b/src/cborjson.h
index 58c4cae..8ff27b9 100644
--- a/src/cborjson.h
+++ b/src/cborjson.h
@@ -58,5 +58,5 @@
}
#endif
-#endif // CBORJSON_H
+#endif /* CBORJSON_H */
diff --git a/src/cborparser.c b/src/cborparser.c
index 1880524..b03e03a 100644
--- a/src/cborparser.c
+++ b/src/cborparser.c
@@ -87,7 +87,7 @@
const CborParser *parser = it->parser;
it->type = CborInvalidType;
- // are we at the end?
+ /* are we at the end? */
if (it->ptr == parser->end)
return CborErrorUnexpectedEOF;
@@ -101,7 +101,7 @@
if (unlikely(descriptor != IndefiniteLength))
return type == CborSimpleType ? CborErrorUnknownType : CborErrorIllegalNumber;
if (likely(!is_fixed_type(type))) {
- // special case
+ /* special case */
it->flags |= CborIteratorFlag_UnknownLength;
it->type = type;
return CborNoError;
@@ -127,7 +127,7 @@
case SinglePrecisionFloat:
case DoublePrecisionFloat:
it->flags |= CborIteratorFlag_IntegerValueTooLarge;
- // fall through
+ /* fall through */
case TrueValue:
case NullValue:
case UndefinedValue:
@@ -149,13 +149,13 @@
case 29:
case 30:
case Break:
- assert(false); // these conditions can't be reached
+ assert(false); /* these conditions can't be reached */
return CborErrorUnexpectedBreak;
}
return CborNoError;
}
- // try to decode up to 16 bits
+ /* try to decode up to 16 bits */
if (descriptor < Value8Bit)
return CborNoError;
@@ -164,20 +164,20 @@
else if (descriptor == Value16Bit)
it->extra = get16(it->ptr + 1);
else
- it->flags |= CborIteratorFlag_IntegerValueTooLarge; // Value32Bit or Value64Bit
+ it->flags |= CborIteratorFlag_IntegerValueTooLarge; /* Value32Bit or Value64Bit */
return CborNoError;
}
static CborError preparse_next_value(CborValue *it)
{
if (it->remaining != UINT32_MAX) {
- // don't decrement the item count if the current item is tag: they don't count
+ /* don't decrement the item count if the current item is tag: they don't count */
if (it->type != CborTagType && !--it->remaining) {
it->type = CborInvalidType;
return CborNoError;
}
} else if (it->remaining == UINT32_MAX && it->ptr != it->parser->end && *it->ptr == (uint8_t)BreakByte) {
- // end of map or array
+ /* end of map or array */
++it->ptr;
it->type = CborInvalidType;
it->remaining = 0;
@@ -217,8 +217,8 @@
assert(value->flags & CborIteratorFlag_IntegerValueTooLarge ||
value->type == CborFloatType || value->type == CborDoubleType);
- // since the additional information can only be Value32Bit or Value64Bit,
- // we just need to test for the one bit those two options differ
+ /* since the additional information can only be Value32Bit or Value64Bit,
+ * we just need to test for the one bit those two options differ */
assert((*value->ptr & SmallValueMask) == Value32Bit || (*value->ptr & SmallValueMask) == Value64Bit);
if ((*value->ptr & 1) == (Value32Bit & 1))
return get32(value->ptr + 1);
@@ -247,7 +247,7 @@
parser->flags = flags;
it->parser = parser;
it->ptr = buffer;
- it->remaining = 1; // there's one type altogether, usually an array or map
+ it->remaining = 1; /* there's one type altogether, usually an array or map */
return preparse_value(it);
}
@@ -277,7 +277,7 @@
return _cbor_value_copy_string(it, NULL, &len, it);
}
- // map or array
+ /* map or array */
if (nestingLevel == CBOR_PARSER_MAX_RECURSIONS)
return CborErrorNestingTooDeep;
@@ -357,8 +357,8 @@
err = preparse_value(recursed);
if (err != CborErrorUnexpectedBreak)
return err;
- // actually, break was expected here
- // it's just an empty container
+ /* actually, break was expected here
+ * it's just an empty container */
++recursed->ptr;
} else {
uint64_t len;
@@ -367,14 +367,14 @@
recursed->remaining = (uint32_t)len;
if (recursed->remaining != len || len == UINT32_MAX) {
- // back track the pointer to indicate where the error occurred
+ /* back track the pointer to indicate where the error occurred */
recursed->ptr = it->ptr;
return CborErrorDataTooLarge;
}
if (recursed->type == CborMapType) {
- // maps have keys and values, so we need to multiply by 2
+ /* maps have keys and values, so we need to multiply by 2 */
if (recursed->remaining > UINT32_MAX / 2) {
- // back track the pointer to indicate where the error occurred
+ /* back track the pointer to indicate where the error occurred */
recursed->ptr = it->ptr;
return CborErrorDataTooLarge;
}
@@ -384,7 +384,7 @@
return preparse_value(recursed);
}
- // the case of the empty container
+ /* the case of the empty container */
recursed->type = CborInvalidType;
recursed->remaining = 0;
return CborNoError;
@@ -480,7 +480,7 @@
++*buflen;
*buffer = malloc(*buflen);
if (!*buffer) {
- // out of memory
+ /* out of memory */
return CborErrorOutOfMemory;
}
err = _cbor_value_copy_string(value, *buffer, buflen, next);
@@ -491,10 +491,10 @@
return CborNoError;
}
-// We return uintptr_t so that we can pass memcpy directly as the iteration
-// function. The choice is to optimize for memcpy, which is used in the base
-// parser API (cbor_value_copy_string), while memcmp is used in convenience API
-// only.
+/* We return uintptr_t so that we can pass memcpy directly as the iteration
+ * function. The choice is to optimize for memcpy, which is used in the base
+ * parser API (cbor_value_copy_string), while memcmp is used in convenience API
+ * only. */
typedef uintptr_t (*IterateFunction)(char *, const uint8_t *, size_t);
static uintptr_t iterate_noop(char *dest, const uint8_t *src, size_t len)
@@ -519,7 +519,7 @@
CborError err;
const uint8_t *ptr = value->ptr;
if (cbor_value_is_length_known(value)) {
- // easy case: fixed length
+ /* easy case: fixed length */
err = extract_length(value->parser, &ptr, &total);
if (err)
return err;
@@ -531,7 +531,7 @@
*result = false;
ptr += total;
} else {
- // chunked
+ /* chunked */
++ptr;
total = 0;
*result = true;
@@ -547,7 +547,7 @@
break;
}
- // is this the right type?
+ /* is this the right type? */
if ((*ptr & MajorTypeMask) != value->type)
return CborErrorIllegalType;
@@ -571,7 +571,7 @@
}
}
- // is there enough room for the ending NUL byte?
+ /* is there enough room for the ending NUL byte? */
if (*result && *buflen > total)
*result = !!func(buffer + total, (const uint8_t *)"", 1);
*buflen = total;
@@ -685,7 +685,7 @@
goto error;
while (!cbor_value_at_end(element)) {
- // find the non-tag so we can compare
+ /* find the non-tag so we can compare */
err = cbor_value_skip_tag(element);
if (err)
goto error;
@@ -699,13 +699,13 @@
if (equals)
return preparse_value(element);
} else {
- // skip this key
+ /* skip this key */
err = cbor_value_advance(element);
if (err)
goto error;
}
- // skip this value
+ /* skip this value */
err = cbor_value_skip_tag(element);
if (err)
goto error;
@@ -714,7 +714,7 @@
goto error;
}
- // not found
+ /* not found */
element->type = CborInvalidType;
return CborNoError;
@@ -731,7 +731,7 @@
{
assert(value->type == CborHalfFloatType);
- // size has been computed already
+ /* size has been computed already */
uint16_t v = get16(value->ptr + 1);
memcpy(result, &v, sizeof(v));
return CborNoError;
diff --git a/src/cborpretty.c b/src/cborpretty.c
index bd0b8ee..36dfdc4 100644
--- a/src/cborpretty.c
+++ b/src/cborpretty.c
@@ -41,7 +41,7 @@
if (r < 0)
return r;
}
- return 0; // should be n * 2, but we don't have the original n anymore
+ return 0; /* should be n * 2, but we don't have the original n anymore */
}
/* This function decodes buffer as UTF-8 and prints as escaped UTF-16.
@@ -52,14 +52,14 @@
while (n--) {
uc = (uint8_t)*buffer++;
if (uc < 0x80) {
- // single-byte UTF-8
+ /* single-byte UTF-8 */
if (uc < 0x7f && uc >= 0x20 && uc != '\\' && uc != '"') {
if (fprintf(out, "%c", (char)uc) < 0)
return CborErrorIO;
continue;
}
- // print as an escape sequence
+ /* print as an escape sequence */
char escaped = (char)uc;
switch (uc) {
case '"':
@@ -88,7 +88,7 @@
continue;
}
- // multi-byte UTF-8, decode it
+ /* multi-byte UTF-8, decode it */
unsigned charsNeeded;
uint32_t min_uc;
if (unlikely(uc <= 0xC1))
@@ -115,7 +115,7 @@
if (n < charsNeeded - 1)
return CborErrorInvalidUtf8TextString;
- // first continuation character
+ /* first continuation character */
uint8_t b = (uint8_t)*buffer++;
if ((b & 0xc0) != 0x80)
return CborErrorInvalidUtf8TextString;
@@ -123,7 +123,7 @@
uc |= b & 0x3f;
if (charsNeeded > 2) {
- // second continuation character
+ /* second continuation character */
b = (uint8_t)*buffer++;
if ((b & 0xc0) != 0x80)
return CborErrorInvalidUtf8TextString;
@@ -131,7 +131,7 @@
uc |= b & 0x3f;
if (charsNeeded > 3) {
- // third continuation character
+ /* third continuation character */
b = (uint8_t)*buffer++;
if ((b & 0xc0) != 0x80)
return CborErrorInvalidUtf8TextString;
@@ -140,20 +140,20 @@
}
}
- // overlong sequence? surrogate pair? out or range?
+ /* overlong sequence? surrogate pair? out or range? */
if (uc < min_uc || uc - 0xd800U < 2048U || uc > 0x10ffff)
return CborErrorInvalidUtf8TextString;
- // now print the sequence
+ /* now print the sequence */
if (charsNeeded > 3) {
- // needs surrogate pairs
+ /* needs surrogate pairs */
if (fprintf(out, "\\u%04" PRIX32 "\\u%04" PRIX32,
- (uc >> 10) + 0xd7c0, // high surrogate
+ (uc >> 10) + 0xd7c0, /* high surrogate */
(uc % 0x0400) + 0xdc00) < 0)
return CborErrorIO;
} else {
print_utf16:
- // no surrogate pair needed
+ /* no surrogate pair needed */
if (fprintf(out, "\\u%04" PRIX32, uc) < 0)
return CborErrorIO;
}
@@ -177,7 +177,7 @@
if (containerType == CborArrayType)
continue;
- // map: that was the key, so get the value
+ /* map: that was the key, so get the value */
if (fprintf(out, ": ") < 0)
return CborErrorIO;
err = value_to_pretty(out, it);
@@ -194,7 +194,7 @@
switch (type) {
case CborArrayType:
case CborMapType: {
- // recursive type
+ /* recursive type */
CborValue recursed;
if (fprintf(out, type == CborArrayType ? "[" : "{") < 0)
@@ -207,16 +207,16 @@
err = cbor_value_enter_container(it, &recursed);
if (err) {
it->ptr = recursed.ptr;
- return err; // parse error
+ return err; /* parse error */
}
err = container_to_pretty(out, &recursed, type);
if (err) {
it->ptr = recursed.ptr;
- return err; // parse error
+ return err; /* parse error */
}
err = cbor_value_leave_container(it, &recursed);
if (err)
- return err; // parse error
+ return err; /* parse error */
if (fprintf(out, type == CborArrayType ? "]" : "}") < 0)
return CborErrorIO;
@@ -225,21 +225,21 @@
case CborIntegerType: {
uint64_t val;
- cbor_value_get_raw_integer(it, &val); // can't fail
+ cbor_value_get_raw_integer(it, &val); /* can't fail */
if (cbor_value_is_unsigned_integer(it)) {
if (fprintf(out, "%" PRIu64, val) < 0)
return CborErrorIO;
} else {
- // CBOR stores the negative number X as -1 - X
- // (that is, -1 is stored as 0, -2 as 1 and so forth)
- if (++val) { // unsigned overflow may happen
+ /* CBOR stores the negative number X as -1 - X
+ * (that is, -1 is stored as 0, -2 as 1 and so forth) */
+ if (++val) { /* unsigned overflow may happen */
if (fprintf(out, "-%" PRIu64, val) < 0)
return CborErrorIO;
} else {
- // overflown
- // 0xffff`ffff`ffff`ffff + 1 =
- // 0x1`0000`0000`0000`0000 = 18446744073709551616 (2^64)
+ /* overflown
+ * 0xffff`ffff`ffff`ffff + 1 =
+ * 0x1`0000`0000`0000`0000 = 18446744073709551616 (2^64) */
if (fprintf(out, "-18446744073709551616") < 0)
return CborErrorIO;
}
@@ -277,7 +277,7 @@
case CborTagType: {
CborTag tag;
- cbor_value_get_tag(it, &tag); // can't fail
+ cbor_value_get_tag(it, &tag); /* can't fail */
if (fprintf(out, "%" PRIu64 "(", tag) < 0)
return CborErrorIO;
err = cbor_value_advance_fixed(it);
@@ -293,7 +293,7 @@
case CborSimpleType: {
uint8_t simple_type;
- cbor_value_get_simple_type(it, &simple_type); // can't fail
+ cbor_value_get_simple_type(it, &simple_type); /* can't fail */
if (fprintf(out, "simple(%" PRIu8 ")", simple_type) < 0)
return CborErrorIO;
break;
@@ -311,7 +311,7 @@
case CborBooleanType: {
bool val;
- cbor_value_get_boolean(it, &val); // can't fail
+ cbor_value_get_boolean(it, &val); /* can't fail */
if (fprintf(out, val ? "true" : "false") < 0)
return CborErrorIO;
break;
@@ -343,11 +343,11 @@
uint64_t ival = (uint64_t)fabs(val);
if (ival == fabs(val)) {
- // this double value fits in a 64-bit integer, so show it as such
- // (followed by a floating point suffix, to disambiguate)
+ /* this double value fits in a 64-bit integer, so show it as such
+ * (followed by a floating point suffix, to disambiguate) */
r = fprintf(out, "%s%" PRIu64 ".%s", val < 0 ? "-" : "", ival, suffix);
} else {
- // this number is definitely not a 64-bit integer
+ /* this number is definitely not a 64-bit integer */
r = fprintf(out, "%." DBL_DECIMAL_DIG_STR "g%s", val, suffix);
}
if (r < 0)
diff --git a/src/cbortojson.c b/src/cbortojson.c
index 48ed8fa..ea36d15 100644
--- a/src/cbortojson.c
+++ b/src/cbortojson.c
@@ -40,12 +40,12 @@
extern FILE *open_memstream(char **bufptr, size_t *sizeptr);
enum ConversionStatusFlags {
- TypeWasNotNative = 0x100, // anything but strings, boolean, null, arrays and maps
+ TypeWasNotNative = 0x100, /* anything but strings, boolean, null, arrays and maps */
TypeWasTagged = 0x200,
NumberPrecisionWasLost = 0x400,
NumberWasNaN = 0x800,
NumberWasInfinite = 0x1000,
- NumberWasNegative = 0x2000, // always used with NumberWasInifite or NumberWasTooBig
+ NumberWasNegative = 0x2000, /* always used with NumberWasInifite or NumberWasTooBig */
FinalTypeMask = 0xff
};
@@ -68,11 +68,11 @@
if (err)
return err;
- // a Base16 (hex) output is twice as big as our buffer
+ /* a Base16 (hex) output is twice as big as our buffer */
buffer = (uint8_t *)malloc(n * 2 + 1);
*result = (char *)buffer;
- // let cbor_value_copy_byte_string know we have an extra byte for the terminating NUL
+ /* let cbor_value_copy_byte_string know we have an extra byte for the terminating NUL */
++n;
err = cbor_value_copy_byte_string(it, buffer + n - 1, &n, it);
assert(err == CborNoError);
@@ -93,23 +93,23 @@
if (err)
return err;
- // a Base64 output (untruncated) has 4 bytes for every 3 in the input
+ /* a Base64 output (untruncated) has 4 bytes for every 3 in the input */
size_t len = (n + 5) / 3 * 4;
out = buffer = (uint8_t *)malloc(len + 1);
*result = (char *)buffer;
- // we read our byte string at the tail end of the buffer
- // so we can do an in-place conversion while iterating forwards
+ /* we read our byte string at the tail end of the buffer
+ * so we can do an in-place conversion while iterating forwards */
in = buffer + len - n;
- // let cbor_value_copy_byte_string know we have an extra byte for the terminating NUL
+ /* let cbor_value_copy_byte_string know we have an extra byte for the terminating NUL */
++n;
err = cbor_value_copy_byte_string(it, in, &n, it);
assert(err == CborNoError);
uint_least32_t val = 0;
for (i = 0; n - i >= 3; i += 3) {
- // read 3 bytes x 8 bits = 24 bits
+ /* read 3 bytes x 8 bits = 24 bits */
if (false) {
#ifdef __GNUC__
} else if (i) {
@@ -120,17 +120,17 @@
val = (in[i] << 16) | (in[i + 1] << 8) | in[i + 2];
}
- // write 4 chars x 6 bits = 24 bits
+ /* write 4 chars x 6 bits = 24 bits */
*out++ = alphabet[(val >> 18) & 0x3f];
*out++ = alphabet[(val >> 12) & 0x3f];
*out++ = alphabet[(val >> 6) & 0x3f];
*out++ = alphabet[val & 0x3f];
}
- // maybe 1 or 2 bytes left
+ /* maybe 1 or 2 bytes left */
if (n - i) {
- // we can read in[i + 1] even if it's past the end of the string because
- // we know (by construction) that it's a NUL byte
+ /* we can read in[i + 1] even if it's past the end of the string because
+ * we know (by construction) that it's a NUL byte */
#ifdef __GNUC__
uint16_t val16;
__builtin_memcpy(&val16, in + i, sizeof(val16));
@@ -140,14 +140,14 @@
#endif
val <<= 8;
- // the 65th character in the alphabet is our filler: either '=' or '\0'
+ /* the 65th character in the alphabet is our filler: either '=' or '\0' */
out[4] = '\0';
out[3] = alphabet[64];
if (n - i == 2) {
- // write the third char in 3 chars x 6 bits = 18 bits
+ /* write the third char in 3 chars x 6 bits = 18 bits */
out[2] = alphabet[(val >> 6) & 0x3f];
} else {
- out[2] = alphabet[64]; // filler
+ out[2] = alphabet[64]; /* filler */
}
out[1] = alphabet[(val >> 12) & 0x3f];
out[0] = alphabet[(val >> 18) & 0x3f];
@@ -176,7 +176,7 @@
{
int flags = status->flags;
if (flags & TypeWasTagged) {
- // extract the tagged type, which may be JSON native
+ /* extract the tagged type, which may be JSON native */
type = flags & FinalTypeMask;
flags &= ~(FinalTypeMask | TypeWasTagged);
@@ -188,7 +188,7 @@
if (!flags)
return CborNoError;
- // print at least the type
+ /* print at least the type */
if (fprintf(out, "\"t\":%d", type) < 0)
return CborErrorIO;
@@ -213,7 +213,7 @@
CborError err = CborNoError;
*type = cbor_value_get_type(it);
while (*type == CborTagType) {
- cbor_value_get_tag(it, tag); // can't fail
+ cbor_value_get_tag(it, tag); /* can't fail */
err = cbor_value_advance_fixed(it);
if (err)
return err;
@@ -229,7 +229,7 @@
CborError err;
if (flags & CborConvertTagsToObjects) {
- cbor_value_get_tag(it, &tag); // can't fail
+ cbor_value_get_tag(it, &tag); /* can't fail */
err = cbor_value_advance_fixed(it);
if (err)
return err;
@@ -259,7 +259,7 @@
return err;
tag = status->lastTag;
- // special handling of byte strings?
+ /* special handling of byte strings? */
if (type == CborByteStringType && (flags & CborConvertByteStringsToBase64Url) == 0 &&
(tag == CborNegativeBignumTag || tag == CborExpectedBase16Tag || tag == CborExpectedBase64Tag)) {
char *str;
@@ -270,7 +270,7 @@
err = dump_bytestring_base64url(&str, it);
} else if (tag == CborExpectedBase64Tag) {
err = dump_bytestring_base64(&str, it);
- } else { // tag == CborExpectedBase16Tag
+ } else { /* tag == CborExpectedBase16Tag */
err = dump_bytestring_base16(&str, it);
}
if (err)
@@ -281,7 +281,7 @@
return err;
}
- // no special handling
+ /* no special handling */
err = value_to_json(out, it, flags, type, status);
status->flags |= TypeWasTagged | type;
return err;
@@ -289,13 +289,13 @@
static CborError stringify_map_key(char **key, CborValue *it, int flags, CborType type)
{
- (void)flags; // unused
- (void)type; // unused
+ (void)flags; /* unused */
+ (void)type; /* unused */
size_t size;
FILE *memstream = open_memstream(key, &size);
if (memstream == NULL)
- return CborErrorOutOfMemory; // could also be EMFILE, but it's unlikely
+ return CborErrorOutOfMemory; /* could also be EMFILE, but it's unlikely */
CborError err = cbor_value_to_pretty_advance(memstream, it);
if (unlikely(fclose(memstream) < 0 || *key == NULL))
@@ -340,15 +340,15 @@
if (err)
return err;
- // first, print the key
+ /* first, print the key */
if (fprintf(out, "\"%s\":", key) < 0)
return CborErrorIO;
- // then, print the value
+ /* then, print the value */
CborType valueType = cbor_value_get_type(it);
err = value_to_json(out, it, flags, valueType, status);
- // finally, print any metadata we may have
+ /* finally, print any metadata we may have */
if (flags & CborConvertAddMetadata) {
if (!err && keyType != CborTextStringType) {
if (fprintf(out, ",\"%s$keycbordump\":true", key) < 0)
@@ -377,12 +377,12 @@
switch (type) {
case CborArrayType:
case CborMapType: {
- // recursive type
+ /* recursive type */
CborValue recursed;
err = cbor_value_enter_container(it, &recursed);
if (err) {
it->ptr = recursed.ptr;
- return err; // parse error
+ return err; /* parse error */
}
if (fputc(type == CborArrayType ? '[' : '{', out) < 0)
return CborErrorIO;
@@ -392,27 +392,27 @@
map_to_json(out, &recursed, flags, status);
if (err) {
it->ptr = recursed.ptr;
- return err; // parse error
+ return err; /* parse error */
}
if (fputc(type == CborArrayType ? ']' : '}', out) < 0)
return CborErrorIO;
err = cbor_value_leave_container(it, &recursed);
if (err)
- return err; // parse error
+ return err; /* parse error */
- status->flags = 0; // reset, there are never conversion errors for us
+ status->flags = 0; /* reset, there are never conversion errors for us */
return CborNoError;
}
case CborIntegerType: {
- double num; // JS numbers are IEEE double precision
+ double num; /* JS numbers are IEEE double precision */
uint64_t val;
- cbor_value_get_raw_integer(it, &val); // can't fail
+ cbor_value_get_raw_integer(it, &val); /* can't fail */
num = (double)val;
if (cbor_value_is_negative_integer(it)) {
- num = -num - 1; // convert to negative
+ num = -num - 1; /* convert to negative */
if ((uint64_t)(-num - 1) != val) {
status->flags = NumberPrecisionWasLost | NumberWasNegative;
status->originalNumber = val;
@@ -423,7 +423,7 @@
status->originalNumber = val;
}
}
- if (fprintf(out, "%.0f", num) < 0) // this number has no fraction, so no decimal points please
+ if (fprintf(out, "%.0f", num) < 0) /* this number has no fraction, so no decimal points please */
return CborErrorIO;
break;
}
@@ -450,7 +450,7 @@
case CborSimpleType: {
uint8_t simple_type;
- cbor_value_get_simple_type(it, &simple_type); // can't fail
+ cbor_value_get_simple_type(it, &simple_type); /* can't fail */
status->flags = TypeWasNotNative;
status->originalNumber = simple_type;
if (fprintf(out, "\"simple(%" PRIu8 ")\"", simple_type) < 0)
@@ -471,7 +471,7 @@
case CborBooleanType: {
bool val;
- cbor_value_get_boolean(it, &val); // can't fail
+ cbor_value_get_boolean(it, &val); /* can't fail */
if (fprintf(out, val ? "true" : "false") < 0)
return CborErrorIO;
break;
@@ -504,11 +504,11 @@
} else {
uint64_t ival = (uint64_t)fabs(val);
if ((double)ival == fabs(val)) {
- // print as integer so we get the full precision
+ /* print as integer so we get the full precision */
r = fprintf(out, "%s%" PRIu64, val < 0 ? "-" : "", ival);
- status->flags |= TypeWasNotNative; // mark this integer number as a double
+ status->flags |= TypeWasNotNative; /* mark this integer number as a double */
} else {
- // this number is definitely not a 64-bit integer
+ /* this number is definitely not a 64-bit integer */
r = fprintf(out, "%." DBL_DECIMAL_DIG_STR "g", val);
}
if (r < 0)
diff --git a/src/compilersupport_p.h b/src/compilersupport_p.h
index ea79851..6c55112 100644
--- a/src/compilersupport_p.h
+++ b/src/compilersupport_p.h
@@ -66,7 +66,7 @@
# define UINT32_MAX (0xffffffffU)
#endif
#ifndef DBL_DECIMAL_DIG
-// DBL_DECIMAL_DIG is C11
+/* DBL_DECIMAL_DIG is C11 */
# define DBL_DECIMAL_DIG 17
#endif
#define DBL_DECIMAL_DIG_STR STRINGIFY(DBL_DECIMAL_DIG)
@@ -142,7 +142,7 @@
#ifdef __cplusplus
# define CONST_CAST(t, v) const_cast<t>(v)
#else
-// C-style const_cast without triggering a warning with -Wcast-qual
+/* C-style const_cast without triggering a warning with -Wcast-qual */
# define CONST_CAST(t, v) (t)(uintptr_t)(v)
#endif
@@ -170,7 +170,7 @@
#if ((defined(__GNUC__) && (__GNUC__ >= 5)) && !defined(__INTEL_COMPILER)) || __has_builtin(__builtin_add_overflow)
return __builtin_add_overflow(v1, v2, r);
#else
- // unsigned additions are well-defined
+ /* unsigned additions are well-defined */
*r = v1 + v2;
return v1 > v1 + v2;
#endif
@@ -185,30 +185,30 @@
memcpy(&v, &val, sizeof(v));
int sign = v >> 63 << 15;
int exp = (v >> 52) & 0x7ff;
- int mant = v << 12 >> 12 >> (53-11); // keep only the 11 most significant bits of the mantissa
+ int mant = v << 12 >> 12 >> (53-11); /* keep only the 11 most significant bits of the mantissa */
exp -= 1023;
if (exp == 1024) {
- // infinity or NaN
+ /* infinity or NaN */
exp = 16;
mant >>= 1;
} else if (exp >= 16) {
- // overflow, as largest number
+ /* overflow, as largest number */
exp = 15;
mant = 1023;
} else if (exp >= -14) {
- // regular normal
+ /* regular normal */
} else if (exp >= -24) {
- // subnormal
+ /* subnormal */
mant |= 1024;
mant >>= -(exp + 14);
exp = -15;
} else {
- // underflow, make zero
+ /* underflow, make zero */
return 0;
}
return sign | ((exp + 15) << 10) | mant;
#endif
}
-#endif // COMPILERSUPPORT_H
+#endif /* COMPILERSUPPORT_H */
diff --git a/src/math_support_p.h b/src/math_support_p.h
index 647ac91..676f781 100644
--- a/src/math_support_p.h
+++ b/src/math_support_p.h
@@ -27,7 +27,7 @@
#include <math.h>
-// this function was copied & adapted from RFC 7049 Appendix D
+/* this function was copied & adapted from RFC 7049 Appendix D */
static inline double decode_half(unsigned short half)
{
#ifdef __F16C__