Skip to content

Commit 516181c

Browse files
committed
path MAINTENANCE clarify string length param
1 parent 64c0b0f commit 516181c

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

src/path.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Michal Vasko <[email protected]>
44
* @brief Path functions
55
*
6-
* Copyright (c) 2020 - 2023 CESNET, z.s.p.o.
6+
* Copyright (c) 2020 - 2025 CESNET, z.s.p.o.
77
*
88
* This source code is licensed under BSD 3-Clause License (the "License").
99
* You may not use this file except in compliance with the License.
@@ -339,6 +339,10 @@ ly_path_parse(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const
339339
LOG_LOCSET(ctx_node, NULL);
340340
}
341341

342+
if (!path_len) {
343+
path_len = strlen(str_path);
344+
}
345+
342346
/* parse as a generic XPath expression, reparse is performed manually */
343347
LY_CHECK_GOTO(ret = lyxp_expr_parse(ctx, str_path, path_len, 0, &exp), error);
344348
tok_idx = 0;

src/path.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct ly_path {
118118
* @param[in] ctx libyang context.
119119
* @param[in] ctx_node Optional context node, used for logging.
120120
* @param[in] str_path Path to parse.
121-
* @param[in] path_len Length of @p str_path.
121+
* @param[in] path_len Length of @p str_path, may be 0 if @p str_path is 0-terminated.
122122
* @param[in] lref Whether leafref is being parsed or not.
123123
* @param[in] begin Begin option (@ref path_begin_options).
124124
* @param[in] prefix Prefix option (@ref path_prefix_options).
@@ -135,7 +135,7 @@ LY_ERR ly_path_parse(const struct ly_ctx *ctx, const struct lysc_node *ctx_node,
135135
* @param[in] ctx libyang context.
136136
* @param[in] cur_node Optional current (original context) node, used for logging.
137137
* @param[in] str_path Path to parse.
138-
* @param[in] path_len Length of @p str_path.
138+
* @param[in] path_len Length of @p str_path, may be 0 if @p str_path is 0-terminated.
139139
* @param[in] prefix Prefix option (@ref path_prefix_options).
140140
* @param[in] pred Predicate option (@ref path_pred_options).
141141
* @param[out] expr Parsed path.

src/tree_data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,8 +3578,8 @@ lyd_find_path(const struct lyd_node *ctx_node, const char *path, ly_bool output,
35783578
LY_CHECK_ARG_RET(NULL, ctx_node, ctx_node->schema, path, LY_EINVAL);
35793579

35803580
/* parse the path */
3581-
ret = ly_path_parse(LYD_CTX(ctx_node), ctx_node->schema, path, strlen(path), 0, LY_PATH_BEGIN_EITHER,
3582-
LY_PATH_PREFIX_FIRST, LY_PATH_PRED_SIMPLE, &expr);
3581+
ret = ly_path_parse(LYD_CTX(ctx_node), ctx_node->schema, path, 0, 0, LY_PATH_BEGIN_EITHER, LY_PATH_PREFIX_FIRST,
3582+
LY_PATH_PRED_SIMPLE, &expr);
35833583
LY_CHECK_GOTO(ret, cleanup);
35843584

35853585
/* compile the path */

src/tree_data_new.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ lyd_new_path_(struct lyd_node *parent, const struct ly_ctx *ctx, const struct ly
16821682
LY_CHECK_GOTO(ret = lyd_new_val_get_format(options, &format), cleanup);
16831683

16841684
/* parse path */
1685-
LY_CHECK_GOTO(ret = ly_path_parse(ctx, NULL, path, strlen(path), 0, LY_PATH_BEGIN_EITHER, LY_PATH_PREFIX_FIRST,
1685+
LY_CHECK_GOTO(ret = ly_path_parse(ctx, NULL, path, 0, 0, LY_PATH_BEGIN_EITHER, LY_PATH_PREFIX_FIRST,
16861686
LY_PATH_PRED_SIMPLE, &exp), cleanup);
16871687

16881688
/* compile path */

src/tree_schema.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* @file tree_schema.c
33
* @author Radek Krejci <[email protected]>
4+
* @author Michal Vasko <[email protected]>
45
* @brief Schema tree implementation
56
*
6-
* Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7+
* Copyright (c) 2015 - 2025 CESNET, z.s.p.o.
78
*
89
* This source code is licensed under BSD 3-Clause License (the "License").
910
* You may not use this file except in compliance with the License.
@@ -631,7 +632,7 @@ lys_find_path_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node,
631632
}
632633

633634
/* parse */
634-
ret = ly_path_parse(ctx, ctx_node, path, strlen(path), 0, LY_PATH_BEGIN_EITHER, LY_PATH_PREFIX_FIRST,
635+
ret = ly_path_parse(ctx, ctx_node, path, 0, 0, LY_PATH_BEGIN_EITHER, LY_PATH_PREFIX_FIRST,
635636
LY_PATH_PRED_SIMPLE, &expr);
636637
LY_CHECK_GOTO(ret, cleanup);
637638

@@ -658,15 +659,15 @@ lys_find_path(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const
658659
LY_ERR ret;
659660
uint8_t oper;
660661

661-
LY_CHECK_ARG_RET(ctx, ctx || ctx_node, NULL);
662+
LY_CHECK_ARG_RET(ctx, ctx || ctx_node, path, NULL);
662663
LY_CHECK_CTX_EQUAL_RET(ctx, ctx_node ? ctx_node->module->ctx : NULL, NULL);
663664

664665
if (!ctx) {
665666
ctx = ctx_node->module->ctx;
666667
}
667668

668669
/* parse */
669-
ret = ly_path_parse(ctx, ctx_node, path, strlen(path), 0, LY_PATH_BEGIN_EITHER, LY_PATH_PREFIX_FIRST,
670+
ret = ly_path_parse(ctx, ctx_node, path, 0, 0, LY_PATH_BEGIN_EITHER, LY_PATH_PREFIX_FIRST,
670671
LY_PATH_PRED_SIMPLE, &expr);
671672
LY_CHECK_GOTO(ret, cleanup);
672673

0 commit comments

Comments
 (0)