[BUG] Segmentation fault in queue.c #158

Closed
opened 2026-01-29 15:05:53 +00:00 by claunia · 2 comments
Owner

Originally created by @Arash1381-y on GitHub (Jun 10, 2023).

Description

In the queue model (path : data_structures/queue/queue.c). dequeue won't work due to a simple bug on the last if clause of it. take a look:
b1a8da69a8/data_structures/queue/queue.c (L65)

as you can see if we have only one variable in our queue on dequeue the HEAD will be null and assigning NULL to NULL->next will cause a segmentation fault.

Expected behavior

not to cause fault =)

Actual behavior

case segmentation fault

Possible fix

simply put line 65 in its above clause

Steps to reproduce

  1. call create
  2. enqueue anything you like
  3. dequeue it

Context

It just don't work =)

Additional information

No response

Originally created by @Arash1381-y on GitHub (Jun 10, 2023). ### Description In the queue model (path : data_structures/queue/queue.c). dequeue won't work due to a simple bug on the last if clause of it. take a look: https://github.com/TheAlgorithms/C/blob/b1a8da69a87cd45e9db0cc340730e4a5e3b36201/data_structures/queue/queue.c#L65 as you can see if we have only one variable in our queue on dequeue the HEAD will be null and assigning NULL to NULL->next will cause a segmentation fault. ### Expected behavior not to cause fault =) ### Actual behavior case segmentation fault ### Possible fix simply put line 65 in its above clause ### Steps to reproduce 1. call create 2. enqueue anything you like 3. dequeue it ### Context It just don't work =) ### Additional information _No response_
claunia added the Stalebug labels 2026-01-29 15:05:53 +00:00
Author
Owner

@github-actions[bot] commented on GitHub (Jul 12, 2023):

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions[bot] commented on GitHub (Jul 12, 2023): This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Author
Owner

@github-actions[bot] commented on GitHub (Jul 19, 2023):

Please ping one of the maintainers once you add more information and updates here. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!

@github-actions[bot] commented on GitHub (Jul 19, 2023): Please ping one of the maintainers once you add more information and updates here. If this is not the case and you need some help, feel free to ask for help in our [Gitter](https://gitter.im/TheAlgorithms) channel or our [Discord server](https://the-algorithms.com/discord/). Thank you for your contributions!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/C#158