lyb BUGFIX several fixes
diff --git a/src/parser_lyb.c b/src/parser_lyb.c
index 07392be..dc47944 100644
--- a/src/parser_lyb.c
+++ b/src/parser_lyb.c
@@ -381,6 +381,7 @@
struct ly_ctx *ctx;
struct lys_module *mod;
char num_str[22], *str;
+ int64_t frac;
uint32_t i, str_len;
uint8_t *value_flags;
const char **value_str;
@@ -469,8 +470,18 @@
*value_str = lydict_insert(ctx, (value->bln ? "true" : "false"), 0);
break;
case LY_TYPE_EMPTY:
+ *value_str = lydict_insert(ctx, "", 0);
+ break;
case LY_TYPE_UNION:
- /* leave value empty */
+ if (attr) {
+ /* we do not support union type attribute */
+ LOGINT(ctx);
+ return -1;
+ }
+
+ if (resolve_union(leaf, type, 1, 2, NULL)) {
+ return -1;
+ }
break;
case LY_TYPE_ENUM:
/* print the value */
@@ -509,8 +520,8 @@
*value_str = lydict_insert(ctx, num_str, 0);
break;
case LY_TYPE_DEC64:
- sprintf(num_str, "%ld.%.*ld", value->dec64 / type->info.dec64.div, type->info.dec64.dig,
- value->dec64 % type->info.dec64.div);
+ frac = value->dec64 % type->info.dec64.div;
+ sprintf(num_str, "%ld.%.*ld", value->dec64 / (int64_t)type->info.dec64.div, frac ? type->info.dec64.dig : 1, frac);
*value_str = lydict_insert(ctx, num_str, 0);
break;
default:
@@ -594,6 +605,15 @@
ret += (r = lyb_parse_val_1(ctx, type, *value_type, *value_flags, data, value_str, value, lybs));
LYB_HAVE_READ_RETURN(r, data, -1);
+ /* union is handled specially */
+ if (type->base == LY_TYPE_UNION) {
+ assert(*value_type == LY_TYPE_STRING);
+
+ *value_str = value->string;
+ value->string = NULL;
+ *value_type = LY_TYPE_UNION;
+ }
+
ret += (r = lyb_parse_val_2(type, leaf, attr, unres));
LYB_HAVE_READ_RETURN(r, data, -1);
@@ -690,6 +710,7 @@
/* unknown attribute, skip it */
do {
ret += (r = lyb_read(data, NULL, lybs->written[lybs->used - 1], lybs));
+ LYB_HAVE_READ_GOTO(r, data, error);
} while (lybs->written[lybs->used - 1]);
goto stop_subtree;
}
@@ -720,6 +741,7 @@
/* attribute value */
ret += (r = lyb_parse_value(type, NULL, attr, data, unres, lybs));
+ LYB_HAVE_READ_GOTO(r, data, error);
stop_subtree:
lyb_read_stop_subtree(lybs);