Skip to content

ASCII_SUBSEQUENCES.cpp: #3135

Description

@18781875724

Issue: Segmentation Fault on Empty Input in Expression Tree Implementation

Description

The expression tree implementation crashes with segmentation fault when an empty string is provided as input. The code attempts to access exp[len-1] without checking if the input string is empty.

Root Cause

  • No input validation for empty strings in constructor
  • Direct access to exp[len-1] where len = 0 causes out-of-bounds access
  • Stack operations proceed with invalid nodes when input is empty

Affected Code

exp_tree(string postfix_exp)
{
    this->postfix_exp = postfix_exp;
    root = NULL;
    create_tree(postfix_exp); // Called without validation
}

void create_tree(string exp)
{
    int len = exp.length();
    root = new node(exp[len-1]); // CRASH: len-1 = -1 when empty
    s.push(root);
    // ... continues processing without checks
}

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