Skip to main content
Code Review

Return to Revisions

2 of 2
Commonmark migration

Bug

When you pop the head node, you never set the new head node's prev pointer to NULL. Same with with popping the tail node: you never set the new tail node's next pointer to NULL.

This can cause a problem later on. Suppose you had the following two element list:

NULL <- A <-> B -> NULL

where head points to A and tail points to B. Now you pop the head node:

(A freed) <- B -> NULL

At this point, both head and tail point to B, but you never set its prev pointer to NULL so it is still pointing at the A node that was freed.

Now if you pop the tail node, your new tail node will be the freed A node, which is a problem.

JS1
  • 28.8k
  • 3
  • 41
  • 83
default

AltStyle によって変換されたページ (->オリジナル) /