C
C copied to clipboard
fix: queue null pointer dereference bug
Description of Change
Fixed a null pointer dereference issue in the dequeue method. If line 61 (if statement) is true, head will be set to null and line 65 (head->next = null) will be executed which leads to a null pointer dereference issue. An example would be removing a node from a queue that contains a single node. Line 66 should be executed in the else statement. Therefore, this fix moves line 66 to be executed in the else statement.
References
Checklist
- [x] Added description of change
- [x] PR title follows semantic commit guidelines
- [x] Search previous suggestions before making a new one, as yours may be a duplicate.
- [x] I acknowledge that all my contributions will be made under the project's license.
Notes: Fixed a null pointer dereference bug (Line 65: Dereferencing a pointer after setting it to null) in the code.