Skip to content

Conversation

@The-AarushiSingh
Copy link

Description of Change

Fixed an out-of-bounds access issue in sorting/counting_sort_string.cpp by pre-allocating the output string with the correct size.

The previous implementation initialized an empty string and wrote to specific indices, causing undefined behavior and potential crashes.
Now, the output string is initialized as string output(n, ' '); to ensure safe memory access and correct sorting behavior.


Checklist

  • Added description of change
  • File name follows File name guidelines
  • Tested with sample inputs to verify correct output
  • Added inline documentation for clarity
  • PR title follows semantic commit guidelines
  • I acknowledge that all my contributions will be made under the project's license

Notes

This PR addresses issue #3055 and ensures countSort runs safely without segmentation faults or memory corruption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant