From e976ffddc1191184bd1b086e787a2631a6785f88 Mon Sep 17 00:00:00 2001 From: zvon Date: Tue, 15 Jan 2019 23:52:15 +0100 Subject: [PATCH] Fix segmentation fault when '.' or '..' is first entry in readdir --- filesystem.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/filesystem.hpp b/filesystem.hpp index 1c4a43e..16a58a4 100644 --- a/filesystem.hpp +++ b/filesystem.hpp @@ -22,6 +22,8 @@ namespace FSLib{ public: Iterator( const Directory &d_ ) : d(opendir(d_.path())) { current_entry = readdir(d); + if( current_entry != nullptr && ( !strcmp(current_entry->d_name, ".") || !strcmp(current_entry->d_name, "..") ) ) + ++(*this); } Iterator( const Directory &d_, const struct dirent *current_entry_) : d(opendir(d_.path())), current_entry(current_entry_) {}