Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX lyd_new_list3 duplicates first key value to the rest of the keys #2206

Closed
wants to merge 1 commit into from
Closed

BUGFIX lyd_new_list3 duplicates first key value to the rest of the keys #2206

wants to merge 1 commit into from

Conversation

adaraiseh
Copy link
Contributor

When using lyd_new_list3 to create using its keys values and lengths, it function only takes the first key value and duplicates it to the other keys:

Example, this function extracts keys from a json object and creates lyd_node:

if (get_list_keys(list, list_obj, lys_flags, &key_values, &values_lengths, &keys_count) == EXIT_SUCCESS) 
{
  // Print keys values:
  printf("Keys content:\n);
  for (int i = 0; i < keys_count; i++) {
    printf("Key %d: %s\n", i, key_values[i]);
  }
  
  // create list
  lyd_new_list3(*parent_data_node, NULL, s_node->name, key_values, values_lengths, 0, &new_data_node);
  
  // print created list
  char *node_print_text;
  lyd_print_mem(&node_print_text, new_data_node, LYD_XML, 0);
  printf("lyd_node:\n);
  printf("%s", node_print_text);
}

The outputs of debugging prints are below:

Keys content:
Key 0: 20
Key 1: 30
lyd_node:
<nh xmlns="urn:okda:iproute2:ip:nexthop">
  <id>20</id>
  <weight>20</weight>
</nh>

As seen the created node had duplicated key 0 to key 1 in the resulting lyd_node.

By checking lyd_new_list3 code, its missing counter i increment which causes the duplication:
https://github.com/CESNET/libyang/blob/master/src/tree_data_new.c#L818

Signed-off-by: Amjad Daraiseh <adaraiseh@okdanetworks.com>
@vjardin
Copy link
Contributor

vjardin commented Mar 21, 2024

Hi @adaraiseh ,

this pull request should be for CESNET:devel and not for CESNET:master.

@adaraiseh
Copy link
Contributor Author

Thanks @vjardin , opened #2207

@adaraiseh adaraiseh closed this Mar 22, 2024
@adaraiseh adaraiseh deleted the fix_list3 branch March 22, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants