aboutsummaryrefslogtreecommitdiff
path: root/src/ucl_schema.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ucl_schema.c')
-rw-r--r--src/ucl_schema.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/ucl_schema.c b/src/ucl_schema.c
index c3aa8a780402..68f01187e375 100644
--- a/src/ucl_schema.c
+++ b/src/ucl_schema.c
@@ -49,7 +49,16 @@ static bool ucl_schema_validate (const ucl_object_t *schema,
/*
* Create validation error
*/
-static void
+
+#ifdef __GNUC__
+static inline void
+ucl_schema_create_error (struct ucl_schema_error *err,
+ enum ucl_schema_error_code code, const ucl_object_t *obj,
+ const char *fmt, ...)
+__attribute__ (( format( printf, 4, 5) ));
+#endif
+
+static inline void
ucl_schema_create_error (struct ucl_schema_error *err,
enum ucl_schema_error_code code, const ucl_object_t *obj,
const char *fmt, ...)
@@ -235,20 +244,22 @@ ucl_schema_validate_object (const ucl_object_t *schema,
/* Additional properties */
if (!allow_additional || additional_schema != NULL) {
/* Check if we have exactly the same properties in schema and object */
- iter = NULL;
+ iter = ucl_object_iterate_new (obj);
prop = ucl_object_lookup (schema, "properties");
- while ((elt = ucl_object_iterate (obj, &iter, true)) != NULL) {
+ while ((elt = ucl_object_iterate_safe (iter, true)) != NULL) {
found = ucl_object_lookup (prop, ucl_object_key (elt));
if (found == NULL) {
/* Try patternProperties */
- piter = NULL;
pat = ucl_object_lookup (schema, "patternProperties");
- while ((pelt = ucl_object_iterate (pat, &piter, true)) != NULL) {
+ piter = ucl_object_iterate_new (pat);
+ while ((pelt = ucl_object_iterate_safe (piter, true)) != NULL) {
found = ucl_schema_test_pattern (obj, ucl_object_key (pelt), true);
if (found != NULL) {
break;
}
}
+ ucl_object_iterate_free (piter);
+ piter = NULL;
}
if (found == NULL) {
if (!allow_additional) {
@@ -267,6 +278,8 @@ ucl_schema_validate_object (const ucl_object_t *schema,
}
}
}
+ ucl_object_iterate_free (iter);
+ iter = NULL;
}
/* Required properties */
if (required != NULL) {
@@ -311,7 +324,7 @@ ucl_schema_validate_number (const ucl_object_t *schema,
if (fabs (remainder (val, constraint)) > alpha) {
ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
"number %.4f is not multiple of %.4f, remainder is %.7f",
- val, constraint);
+ val, constraint, remainder (val, constraint));
ret = false;
break;
}
@@ -371,7 +384,7 @@ ucl_schema_validate_string (const ucl_object_t *schema,
constraint = ucl_object_toint (elt);
if (obj->len > constraint) {
ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
- "string is too big: %.3f, maximum is: %.3f",
+ "string is too big: %u, maximum is: %" PRId64,
obj->len, constraint);
ret = false;
break;
@@ -382,7 +395,7 @@ ucl_schema_validate_string (const ucl_object_t *schema,
constraint = ucl_object_toint (elt);
if (obj->len < constraint) {
ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
- "string is too short: %.3f, minimum is: %.3f",
+ "string is too short: %u, minimum is: %" PRId64,
obj->len, constraint);
ret = false;
break;