Skip to content

Conversation

Ardival
Copy link
Contributor

@Ardival Ardival commented Oct 14, 2025

No description provided.

Copy link
Member

@michalvasko michalvasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the test

src/diff.c Outdated
/**
* @brief In user-ordered lists, certain operations on sibling nodes can result in logically identical changes.
* However, applying the first change may cause the second one to fail.
* To prevent this, the affected node is unlinked.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the affected node is freed, not just unlinked.

src/diff.c Outdated
size_t bufflen1 = 0, buffused1 = 0;
size_t bufflen2 = 0, buffused2 = 0;

/* Itereate throught previous nodes and look for logically identical changes */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo and please keep the exact same comment formatting, starts with a lowercase letter.

src/diff.c Outdated
size_t bufflen2 = 0, buffused2 = 0;

/* Itereate throught previous nodes and look for logically identical changes */
while (diff_iter->prev->next != NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!= NULL is redundant and we do not write it.

src/diff.c Outdated
metas[1] = lyd_find_meta(diff_iter->meta, mod, "orig-key");

/* If keys don't match, skip - not a candidate for cyclic change */
if (strcmp(lyd_get_meta_value(metas[0]), lyd_get_meta_value(metas[1]))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the metadata guaranteed to be found? Otherwise you get a SEGFAULT.

src/diff.c Outdated
Comment on lines 2057 to 2061
if ((ret = lyd_unlink_tree(*diff))) {
return ret;
}

lyd_free_all(*diff);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be implemented by simply calling lyd_free_tree(*diff).

src/diff.c Outdated
Comment on lines 2068 to 2075
free(buff1);
buff1 = NULL;
bufflen1 = 0;
buffused1 = 0;
free(buff2);
buff2 = NULL;
bufflen2 = 0;
buffused2 = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good candidate for a cleanup label where everything is freed. In between iterations it should be enough to zero buffused.

src/diff.c Outdated
ret = lyd_diff_merge_replace(&diff_node, cur_op, src_diff);

/* diff_node was unlinked and do not need any further changes */
if (!diff_node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up for a discussion, redundant nodes are detected in lyd_diff_is_redundant() at the function end, perhaps that is where the check should be.

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