|
|
|
@ -639,7 +639,6 @@ static void cyaml__handle_replay(
@@ -639,7 +639,6 @@ static void cyaml__handle_replay(
|
|
|
|
|
* object. |
|
|
|
|
* |
|
|
|
|
* \param[in] ctx The CYAML loading context. |
|
|
|
|
* \return \ref CYAML_OK on success, or appropriate error otherwise. |
|
|
|
|
*/ |
|
|
|
|
static void cyaml__delete_yaml_event( |
|
|
|
|
cyaml_ctx_t *ctx) |
|
|
|
@ -879,17 +878,20 @@ static cyaml_err_t cyaml__mapping_bitfieid_create(
@@ -879,17 +878,20 @@ static cyaml_err_t cyaml__mapping_bitfieid_create(
|
|
|
|
|
cyaml_ctx_t *ctx, |
|
|
|
|
cyaml_state_t *state) |
|
|
|
|
{ |
|
|
|
|
cyaml_bitfield_t *bitfield; |
|
|
|
|
unsigned count = state->mapping.fields_count; |
|
|
|
|
size_t size = ((count + CYAML_BITFIELD_BITS - 1) / CYAML_BITFIELD_BITS) |
|
|
|
|
* sizeof(*bitfield); |
|
|
|
|
|
|
|
|
|
bitfield = cyaml__alloc(ctx->config, size, true); |
|
|
|
|
if (bitfield == NULL) { |
|
|
|
|
return CYAML_ERR_OOM; |
|
|
|
|
} |
|
|
|
|
if (count != 0) { |
|
|
|
|
cyaml_bitfield_t *bitfield; |
|
|
|
|
size_t size = ((count + CYAML_BITFIELD_BITS - 1) / |
|
|
|
|
CYAML_BITFIELD_BITS) * sizeof(*bitfield); |
|
|
|
|
|
|
|
|
|
state->mapping.fields_set = bitfield; |
|
|
|
|
bitfield = cyaml__alloc(ctx->config, size, true); |
|
|
|
|
if (bitfield == NULL) { |
|
|
|
|
return CYAML_ERR_OOM; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
state->mapping.fields_set = bitfield; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return CYAML_OK; |
|
|
|
|
} |
|
|
|
@ -1312,6 +1314,9 @@ static cyaml_err_t cyaml__read_int(
@@ -1312,6 +1314,9 @@ static cyaml_err_t cyaml__read_int(
|
|
|
|
|
|
|
|
|
|
if (end == value || errno == ERANGE || |
|
|
|
|
temp < min || temp > max) { |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_ERROR, |
|
|
|
|
"Load: Invalid INT value: '%s'\n", |
|
|
|
|
value); |
|
|
|
|
return CYAML_ERR_INVALID_VALUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1321,11 +1326,13 @@ static cyaml_err_t cyaml__read_int(
@@ -1321,11 +1326,13 @@ static cyaml_err_t cyaml__read_int(
|
|
|
|
|
/**
|
|
|
|
|
* Helper to read a number into a uint64_t. |
|
|
|
|
* |
|
|
|
|
* \param[in] ctx The CYAML loading context. |
|
|
|
|
* \param[in] value String containing scaler value. |
|
|
|
|
* \param[in] out The place to write the value in the output data. |
|
|
|
|
* \return \ref CYAML_OK on success, or appropriate error code otherwise. |
|
|
|
|
*/ |
|
|
|
|
static inline cyaml_err_t cyaml__read_uint64_t( |
|
|
|
|
const cyaml_ctx_t *ctx, |
|
|
|
|
const char *value, |
|
|
|
|
uint64_t *out) |
|
|
|
|
{ |
|
|
|
@ -1336,6 +1343,9 @@ static inline cyaml_err_t cyaml__read_uint64_t(
@@ -1336,6 +1343,9 @@ static inline cyaml_err_t cyaml__read_uint64_t(
|
|
|
|
|
temp = strtoull(value, &end, 0); |
|
|
|
|
|
|
|
|
|
if (end == value || errno == ERANGE) { |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_ERROR, |
|
|
|
|
"Load: Invalid uint64_t value: '%s'\n", |
|
|
|
|
value); |
|
|
|
|
return CYAML_ERR_INVALID_VALUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1368,13 +1378,16 @@ static cyaml_err_t cyaml__read_uint(
@@ -1368,13 +1378,16 @@ static cyaml_err_t cyaml__read_uint(
|
|
|
|
|
return CYAML_ERR_INVALID_DATA_SIZE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err = cyaml__read_uint64_t(value, &temp); |
|
|
|
|
err = cyaml__read_uint64_t(ctx, value, &temp); |
|
|
|
|
if (err != CYAML_OK) { |
|
|
|
|
return err; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
max = (~(uint64_t)0) >> ((8 - schema->data_size) * 8); |
|
|
|
|
if (temp > max) { |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_ERROR, |
|
|
|
|
"Load: Invalid UINT value: '%s'\n", |
|
|
|
|
value); |
|
|
|
|
return CYAML_ERR_INVALID_VALUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1398,7 +1411,7 @@ static cyaml_err_t cyaml__read_bool(
@@ -1398,7 +1411,7 @@ static cyaml_err_t cyaml__read_bool(
|
|
|
|
|
{ |
|
|
|
|
bool temp = true; |
|
|
|
|
static const char * const false_strings[] = { |
|
|
|
|
"false", "no", "disable", "0", |
|
|
|
|
"false", "no", "off", "disable", "0", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
CYAML_UNUSED(ctx); |
|
|
|
@ -1440,11 +1453,14 @@ static cyaml_err_t cyaml__read_enum(
@@ -1440,11 +1453,14 @@ static cyaml_err_t cyaml__read_enum(
|
|
|
|
|
|
|
|
|
|
if (schema->flags & CYAML_FLAG_STRICT) { |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_ERROR, |
|
|
|
|
"Load: Invalid enumeration value: %s\n", value); |
|
|
|
|
"Load: Invalid ENUM value: %s\n", value); |
|
|
|
|
return CYAML_ERR_INVALID_VALUE; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_DEBUG, |
|
|
|
|
"Load: Attempt numerical fallback for ENUM: " |
|
|
|
|
"'%s'\n", value); |
|
|
|
|
return cyaml__read_int(ctx, schema, value, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1472,9 +1488,11 @@ static cyaml_err_t cyaml__read_float_f(
@@ -1472,9 +1488,11 @@ static cyaml_err_t cyaml__read_float_f(
|
|
|
|
|
CYAML_UNUSED(schema); |
|
|
|
|
|
|
|
|
|
errno = 0; |
|
|
|
|
temp = strtof(value, &end); |
|
|
|
|
temp = (float) strtod(value, &end); |
|
|
|
|
|
|
|
|
|
if (end == value || errno == ERANGE) { |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_ERROR, |
|
|
|
|
"Load: Invalid FLOAT value: %s\n", value); |
|
|
|
|
return CYAML_ERR_INVALID_VALUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1510,6 +1528,8 @@ static cyaml_err_t cyaml__read_float_d(
@@ -1510,6 +1528,8 @@ static cyaml_err_t cyaml__read_float_d(
|
|
|
|
|
temp = strtod(value, &end); |
|
|
|
|
|
|
|
|
|
if (end == value || errno == ERANGE) { |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_ERROR, |
|
|
|
|
"Load: Invalid FLOAT value: %s\n", value); |
|
|
|
|
return CYAML_ERR_INVALID_VALUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1591,8 +1611,14 @@ static cyaml_err_t cyaml__read_string(
@@ -1591,8 +1611,14 @@ static cyaml_err_t cyaml__read_string(
|
|
|
|
|
if (schema->string.min > schema->string.max) { |
|
|
|
|
return CYAML_ERR_BAD_MIN_MAX_SCHEMA; |
|
|
|
|
} else if (str_len < schema->string.min) { |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_ERROR, |
|
|
|
|
"Load: STRING length < %"PRIu32": %s\n", |
|
|
|
|
schema->string.min, value); |
|
|
|
|
return CYAML_ERR_STRING_LENGTH_MIN; |
|
|
|
|
} else if (str_len > schema->string.max) { |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_ERROR, |
|
|
|
|
"Load: STRING length > %"PRIu32": %s\n", |
|
|
|
|
schema->string.max, value); |
|
|
|
|
return CYAML_ERR_STRING_LENGTH_MAX; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1818,7 +1844,7 @@ static cyaml_err_t cyaml__set_bitval(
@@ -1818,7 +1844,7 @@ static cyaml_err_t cyaml__set_bitval(
|
|
|
|
|
|
|
|
|
|
switch (cyaml__get_event_type(event)) { |
|
|
|
|
case CYAML_EVT_SCALAR: |
|
|
|
|
err = cyaml__read_uint64_t( |
|
|
|
|
err = cyaml__read_uint64_t(ctx, |
|
|
|
|
(const char *)event->data.scalar.value, &value); |
|
|
|
|
if (err != CYAML_OK) { |
|
|
|
|
return err; |
|
|
|
@ -2206,7 +2232,7 @@ static cyaml_err_t cyaml__map_key(
@@ -2206,7 +2232,7 @@ static cyaml_err_t cyaml__map_key(
|
|
|
|
|
cyaml_event_t cyaml_event; |
|
|
|
|
if (!(ctx->config->flags & |
|
|
|
|
CYAML_CFG_IGNORE_UNKNOWN_KEYS)) { |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_DEBUG, |
|
|
|
|
cyaml__log(ctx->config, CYAML_LOG_ERROR, |
|
|
|
|
"Load: Unexpected key: %s\n", key); |
|
|
|
|
return CYAML_ERR_INVALID_KEY; |
|
|
|
|
} |
|
|
|
|