The capacity of the xpath string was not guaranteed to be sufficient to hold all
the key predicates and so would truncate. Calculate the required space and
guarantee that it is available.
Signed-off-by: Christian Hopps <chopps@labn.net>
*/
len = darr_strlen(ys->xpath);
if (ni->keys.num) {
- yang_get_key_preds(ys->xpath + len, sib,
- &ni->keys,
+ darr_ensure_avail(ys->xpath,
+ yang_get_key_pred_strlen(sib, &ni->keys) + 1);
+ yang_get_key_preds(ys->xpath + len, sib, &ni->keys,
darr_cap(ys->xpath) - len);
} else {
/* add a position predicate (1s based?) */
} while (node);
return count;
}
+int yang_get_key_pred_strlen(const struct lysc_node *snode, const struct yang_list_keys *keys)
+{
+ const struct lysc_node_leaf *skey;
+ size_t len = 0;
+ size_t i = 0;
+
+ LY_FOR_KEYS (snode, skey) {
+ /* [%s='%s'] */
+ len += 5 + strlen(skey->name) + strlen(keys->key[i]);
+ i++;
+ }
+ return len;
+}
-int yang_get_key_preds(char *s, const struct lysc_node *snode, const struct yang_list_keys *keys,
- ssize_t space)
+int yang_get_key_preds(char *s, const struct lysc_node *snode, const struct yang_list_keys *keys, ssize_t space)
{
const struct lysc_node_leaf *skey;
ssize_t len2, len = 0;
extern int yang_get_key_preds(char *s, const struct lysc_node *snode,
const struct yang_list_keys *keys, ssize_t space);
+/* Get the length of the predicate string based on the keys */
+extern int yang_get_key_pred_strlen(const struct lysc_node *snode,
+ const struct yang_list_keys *keys);
+
/* Get YANG keys from an existing dnode */
extern int yang_get_node_keys(struct lyd_node *node, struct yang_list_keys *keys);