Skip to content

Segmentation Fault on Empty Queue #16

@yashi-here

Description

@yashi-here

Location: Queue_using_stack.cpp Issue: Lack of underflow protection in pop() and peek() functions.

Analysis: The code directly calls s1.top() (or s2.top()) without verifying if the stacks contain any elements. In C++, calling .top() on an empty std::stack is undefined behavior and leads to a Segmentation Fault (program crash). A robust implementation must check if (s1.empty()) before attempting to access the top element.

Impact: Any user calling dequeue on an empty queue will cause the entire application to crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions