Skip to content

Commit 20b8b81

Browse files
committed
lyb UPDATE move feature count read
1 parent d7bb9cd commit 20b8b81

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

src/parser_lyb.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,22 +386,25 @@ lyb_check_mod_revision(struct lyd_lyb_ctx *lybctx, const char *mod_name, const c
386386
*
387387
* @param[in] lybctx LYB context.
388388
* @param[in] mod_name Module name from LYB data.
389-
* @param[in] feature_count Number of features in LYB data.
390389
* @param[in] mod Module from parser context.
391390
* @return LY_ERR value.
392391
*/
393392
static LY_ERR
394-
lyb_check_mod_features(struct lyd_lyb_ctx *lybctx, const char *mod_name, uint32_t feature_count,
395-
const struct lys_module *mod)
393+
lyb_check_mod_features(struct lyd_lyb_ctx *lybctx, const char *mod_name, const struct lys_module *mod)
396394
{
397395
LY_ERR rc = LY_SUCCESS;
398396
struct lylyb_parse_ctx *pctx = lybctx->parse_ctx;
399397
char *feature_name = NULL, **features = NULL, *en_feats_printer = NULL, *en_feats_parser = NULL;
400-
uint32_t i, ctx_feature_count, len;
398+
uint32_t i, feature_count, ctx_feature_count, len;
399+
400+
/* read feature count */
401+
lyb_read_count(&feature_count, pctx);
401402

402-
/* create an array for the features */
403-
features = calloc(feature_count, sizeof *features);
404-
LY_CHECK_ERR_RET(!features, LOGMEM(pctx->ctx), LY_EMEM);
403+
if (feature_count) {
404+
/* create an array for the features */
405+
features = calloc(feature_count, sizeof *features);
406+
LY_CHECK_ERR_RET(!features, LOGMEM(pctx->ctx), LY_EMEM);
407+
}
405408

406409
/* read all features from LYB data */
407410
for (i = 0; i < feature_count; i++) {
@@ -488,7 +491,6 @@ lyb_parse_module(struct lyd_lyb_ctx *lybctx, const struct lys_module **mod)
488491
struct lylyb_parse_ctx *pctx = lybctx->parse_ctx;
489492
char *mod_name = NULL, mod_rev[LY_REV_SIZE];
490493
uint16_t rev;
491-
uint32_t feature_count = 0;
492494

493495
mod_rev[0] = '\0';
494496

@@ -514,11 +516,8 @@ lyb_parse_module(struct lyd_lyb_ctx *lybctx, const struct lys_module **mod)
514516
/* revision check */
515517
LY_CHECK_GOTO(rc = lyb_check_mod_revision(lybctx, mod_name, mod_rev, *mod), cleanup);
516518

517-
/* feature count */
518-
lyb_read_count(&feature_count, pctx);
519-
520519
/* features and feature check */
521-
LY_CHECK_GOTO(rc = lyb_check_mod_features(lybctx, mod_name, feature_count, *mod), cleanup);
520+
LY_CHECK_GOTO(rc = lyb_check_mod_features(lybctx, mod_name, *mod), cleanup);
522521

523522
cleanup:
524523
free(mod_name);

0 commit comments

Comments
 (0)