Archived
Parser: inline the cbor_value_get_half_float() function
It was originally non-inline because I had thought of doing conversions from half-float to float and onwards to double, but I never actually made that in the API. Instead, even the get_float() and get_double(), we only memcpy anyway and leave it up to the upper layer to convert, as needed. This change triggered an use-when-uninitialised false positive warning that I needed to work around in the validator. Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
+9
-2
@@ -513,9 +513,16 @@ CBOR_API CborError cbor_value_map_find_value(const CborValue *map, const char *s
|
||||
/* Floating point */
|
||||
CBOR_INLINE_API bool cbor_value_is_half_float(const CborValue *value)
|
||||
{ return value->type == CborHalfFloatType; }
|
||||
CBOR_PRIVATE_API uint16_t _cbor_value_get_half_float_helper(const CborValue *value);
|
||||
CBOR_API CborError cbor_value_get_half_float(const CborValue *value, void *result);
|
||||
CBOR_API CborError cbor_value_get_half_float_as_float(const CborValue *value, float *result);
|
||||
CBOR_INLINE_API CborError cbor_value_get_half_float(const CborValue *value, void *result)
|
||||
{
|
||||
assert(cbor_value_is_half_float(value));
|
||||
assert((value->flags & CborIteratorFlag_IntegerValueTooLarge) == 0);
|
||||
|
||||
/* size has already been computed */
|
||||
memcpy(result, &value->extra, sizeof(value->extra));
|
||||
return CborNoError;
|
||||
}
|
||||
|
||||
CBOR_INLINE_API bool cbor_value_is_float(const CborValue *value)
|
||||
{ return value->type == CborFloatType; }
|
||||
|
||||
+2
-25
@@ -1504,6 +1504,8 @@ error:
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn CborError cbor_value_get_half_float(const CborValue *value, void *result)
|
||||
*
|
||||
* Retrieves the CBOR half-precision floating point (16-bit) value that \a
|
||||
* value points to and stores it in \a result. If the iterator \a value does
|
||||
* not point to a half-precision floating point value, the behavior is
|
||||
@@ -1516,30 +1518,5 @@ error:
|
||||
*
|
||||
* \sa cbor_value_get_type(), cbor_value_is_valid(), cbor_value_is_half_float(), cbor_value_get_half_float_as_float(), cbor_value_get_float()
|
||||
*/
|
||||
CborError cbor_value_get_half_float(const CborValue *value, void *result)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
v = _cbor_value_get_half_float_helper(value);
|
||||
memcpy(result, &v, sizeof(v));
|
||||
|
||||
return CborNoError;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
*
|
||||
* Retrieves the CBOR half-precision floating point value binary
|
||||
* representation as 16-bit unsigned integer.
|
||||
* The result can be used as-is, e.g. to copy bitwise into the
|
||||
* system-dependent half-precision floating point type, or it can be
|
||||
* converted to the C language standard floating point type
|
||||
* (float or double).
|
||||
*/
|
||||
CBOR_PRIVATE_API uint16_t _cbor_value_get_half_float_helper(const CborValue *value)
|
||||
{
|
||||
cbor_assert(cbor_value_is_half_float(value));
|
||||
/* size has been computed already */
|
||||
return get16(value->ptr + 1);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -44,8 +44,8 @@
|
||||
CborError cbor_value_get_half_float_as_float(const CborValue *value, float *result)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
v = _cbor_value_get_half_float_helper(value);
|
||||
CborError err = cbor_value_get_half_float(value, &v);
|
||||
cbor_assert(err == CborNoError);
|
||||
|
||||
*result = (float)decode_half((unsigned short)v);
|
||||
|
||||
|
||||
@@ -380,7 +380,7 @@ static inline CborError validate_floating_point(CborValue *it, CborType type, ui
|
||||
int r;
|
||||
double val;
|
||||
float valf;
|
||||
uint16_t valf16;
|
||||
uint16_t valf16 = 0x7c01; /* dummy value, an infinity */
|
||||
|
||||
if (type != CborDoubleType) {
|
||||
if (type == CborFloatType) {
|
||||
|
||||
Reference in New Issue
Block a user