{"action":"closed","issue":{"url":"https://api.github.com/repos/CESNET/libyang/issues/19","repository_url":"https://api.github.com/repos/CESNET/libyang","labels_url":"https://api.github.com/repos/CESNET/libyang/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/CESNET/libyang/issues/19/comments","events_url":"https://api.github.com/repos/CESNET/libyang/issues/19/events","html_url":"https://github.com/CESNET/libyang/issues/19","id":132376696,"number":19,"title":"lyd_insert_after sets prev/next pointers incorrectly","user":{"login":"lukasmacko","id":16013493,"avatar_url":"https://avatars.githubusercontent.com/u/16013493?v=3","gravatar_id":"","url":"https://api.github.com/users/lukasmacko","html_url":"https://github.com/lukasmacko","followers_url":"https://api.github.com/users/lukasmacko/followers","following_url":"https://api.github.com/users/lukasmacko/following{/other_user}","gists_url":"https://api.github.com/users/lukasmacko/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasmacko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasmacko/subscriptions","organizations_url":"https://api.github.com/users/lukasmacko/orgs","repos_url":"https://api.github.com/users/lukasmacko/repos","events_url":"https://api.github.com/users/lukasmacko/events{/privacy}","received_events_url":"https://api.github.com/users/lukasmacko/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"rkrejci","id":6471899,"avatar_url":"https://avatars.githubusercontent.com/u/6471899?v=3","gravatar_id":"","url":"https://api.github.com/users/rkrejci","html_url":"https://github.com/rkrejci","followers_url":"https://api.github.com/users/rkrejci/followers","following_url":"https://api.github.com/users/rkrejci/following{/other_user}","gists_url":"https://api.github.com/users/rkrejci/gists{/gist_id}","starred_url":"https://api.github.com/users/rkrejci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkrejci/subscriptions","organizations_url":"https://api.github.com/users/rkrejci/orgs","repos_url":"https://api.github.com/users/rkrejci/repos","events_url":"https://api.github.com/users/rkrejci/events{/privacy}","received_events_url":"https://api.github.com/users/rkrejci/received_events","type":"User","site_admin":false},"milestone":null,"comments":0,"created_at":"2016-02-09T10:01:56Z","updated_at":"2016-02-09T14:15:58Z","closed_at":"2016-02-09T14:15:58Z","body":"The program creates node in order l1, l2, l3 and the tries to adjust the order to be l2, l1, l3.\r\n```C\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <libyang/libyang.h>\r\n\r\nint main(int argc, char **argv)\r\n{\r\n    struct ly_ctx *ctx = ly_ctx_new(\".\");\r\n    const struct lys_module *test_module = ly_ctx_load_module(ctx, \"test-module\", NULL);\r\n\r\n    if (NULL == test_module){\r\n        puts(\"load module failed\");\r\n        return 1;\r\n    }   \r\n\r\n    struct lyd_node *l1 = lyd_new(NULL, test_module, \"list\");\r\n    lyd_new_leaf(l1, test_module, \"key\", \"A\");\r\n\r\n    struct lyd_node *l2 = lyd_new(NULL, test_module, \"list\");\r\n    lyd_new_leaf(l2, test_module, \"key\", \"B\");\r\n\r\n\r\n    struct lyd_node *l3 = lyd_new(NULL, test_module, \"list\");\r\n    lyd_new_leaf(l3, test_module, \"key\", \"C\");\r\n\r\n    lyd_insert_after(l1, l2);\r\n    lyd_insert_after(l2, l3);\r\n\r\n    /* ERROR*/\r\n    lyd_insert_after(l2, l1); \r\n\r\n   /* THIS WORK as expected\r\n    lyd_insert_before(l1, l2); */\r\n\r\n    lyd_free_withsiblings(l1);\r\n\r\n    ly_ctx_destroy(ctx, NULL);\r\n    return 0;\r\n}\r\n\r\n```\r\nIt might be related to the fact that reordered nodes has no parent (top-level nodes)\r\n\r\nThe program sets pointer like this:\r\n![incorrect](https://cloud.githubusercontent.com/assets/16013493/12912915/f1c136bc-cf1b-11e5-80c0-cc725911a048.PNG)\r\n\r\nThe expected state(in comment):\r\n![expected](https://cloud.githubusercontent.com/assets/16013493/12912930/05f92bb2-cf1c-11e5-9e85-d03969e290d3.PNG)\r\n\r\n\r\ntest-module.yang\r\n```YANG\r\nmodule test-module {\r\n  namespace \"urn:ietf:params:xml:ns:yang:test-module\";\r\n  prefix tm;\r\n\r\n  organization \"organization\";\r\n  description\r\n    \"example yang module\";\r\n \r\n  list list {\r\n    key \"key\";\r\n    leaf key {\r\n      type string;\r\n    }\r\n  }\r\n}\r\n```"}}