Skip to content

Commit

Permalink
Fix out of range error in file extension check (#99)
Browse files Browse the repository at this point in the history
This pull request fixes an issue where attempting to check the file
extension using substr could cause an out of range error if the file
name is shorter than 3 characters.
Added a condition to ensure the file name length is at least 3 before
performing the substr operation.
It will prevent potential crashes or undefined behavior when handling
short file names.
  • Loading branch information
ofecisrael authored Dec 2, 2024
1 parent 71758c6 commit bf71098
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int main( int argc, char* argv[] )
else
{
// whether it is a signature is determined by file extension *.eo.
bool isSignature = (file.substr(file.size()-3)==".eo");
bool isSignature = (file.size() >= 3 && file.substr(file.size()-3)==".eo");
// include the file
if (!s.includeFile(file, isSignature))
{
Expand Down

0 comments on commit bf71098

Please sign in to comment.