Skip to content

Commit bec451a

Browse files
committed
Enable pedantic compiler flags and fix new pedantic errors
1 parent 8ad85d8 commit bec451a

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ set(NOTIFYCPP_SOURCES
5656
source/notify_controller.cpp
5757
source/notify.cpp)
5858

59-
# XXX readlink
60-
#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic " CACHE STRING "Set C++ Compiler Flags" FORCE)
59+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic "
60+
CACHE STRING "Set C++ Compiler Flags" FORCE)
6161

6262

6363
# Offer the user the choice of overriding the installation directories

source/fanotify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ TFileSystemEventPtr Fanotify::getNextEvent()
162162

163163
/* fanotify event received? */
164164
if (fds[FD_POLL_FANOTIFY].revents & POLLIN) {
165-
char buffer[_fanotify_buffer_size];
165+
std::vector<char> buffer(_fanotify_buffer_size);
166166
ssize_t length;
167167

168168
/* Read from the FD. It will read all events available up to
169169
* the given buffer size. */
170-
if ((length = read(fds[FD_POLL_FANOTIFY].fd, buffer, _fanotify_buffer_size)) > 0) {
170+
if ((length = read(fds[FD_POLL_FANOTIFY].fd, buffer.data(), _fanotify_buffer_size)) > 0) {
171171

172-
auto metadata = reinterpret_cast<fanotify_event_metadata*>(buffer);
172+
auto metadata = reinterpret_cast<fanotify_event_metadata*>(buffer.data());
173173

174174
while (FAN_EVENT_OK(metadata, length) && isRunning()) {
175175

source/notify.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,19 @@ bool Notify::isIgnored(const std::filesystem::path& p) const
8686

8787
std::string Notify::getFilePath(int fd) const
8888
{
89-
ssize_t len;
9089
char buffer[PATH_MAX];
9190

9291
if (fd <= 0)
9392
return {};
9493

95-
sprintf(buffer, "/proc/self/fd/%d", fd);
96-
if ((len = readlink(buffer, buffer, PATH_MAX - 1)) < 0)
94+
std::string linkPath = "/proc/self/fd/" + std::to_string(fd);
95+
96+
ssize_t len = readlink(linkPath.c_str(), buffer, PATH_MAX - 1);
97+
if (len < 0)
9798
return {};
9899

99100
buffer[len] = '\0';
100-
return std::string(buffer);
101+
return std::string(buffer, len);
101102
}
102103

103104
bool Notify::checkWatchFile(const FileSystemEvent& fse) const

test/unit/event_handler_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TEST_CASE("EventOperatorTest")
3030
CHECK_EQ((Event::all & Event::close_write), Event::close_write);
3131
CHECK_EQ((Event::close & Event::close_write), Event::close_write);
3232
CHECK_EQ((Event::all & Event::close), Event::close);
33-
CHECK_EQ((Event::all & Event::access | Event::modify), Event::access | Event::modify);
33+
CHECK_EQ((Event::all & (Event::access | Event::modify)), Event::access | Event::modify);
3434
CHECK_EQ((Event::all & Event::moved_from), Event::moved_from);
3535
CHECK_EQ((Event::move & Event::moved_from), Event::moved_from);
3636
CHECK_FALSE((Event::move & Event::open) == Event::open);

test/unit/fanotify_controller_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldWatchPathRecursively")
188188
case Event::open:
189189
promisedOpen_.set_value(notification);
190190
break;
191+
default:
192+
break;
191193
}
192194

193195
});

test/unit/inotify_controller_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ TEST_CASE_FIXTURE(FilesystemEventHelper, "shouldWatchPathRecursively")
175175
case Event::open:
176176
promisedOpen_.set_value(notification);
177177
break;
178+
default:
179+
break;
178180
}
179181

180182
});

0 commit comments

Comments
 (0)