From aa63889e5beaddfa8e260321eb4c9e569d088786 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Tue, 18 Aug 2020 21:58:51 +0200 Subject: [PATCH] Enable bugprone-terminating-continue clang-tidy check Signed-off-by: Kevin Ottens --- .clang-tidy | 1 + src/gui/folderwatcher_linux.cpp | 34 ++++++++++++++++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 302f6a3ce..436a6c7de 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,6 +5,7 @@ Checks: '-*, bugprone-macro-parentheses, bugprone-narrowing-conversions, bugprone-too-small-loop-variable, + bugprone-terminating-continue, cppcoreguidelines-init-variables, misc-*, -misc-non-private-member-variables-in-classes, diff --git a/src/gui/folderwatcher_linux.cpp b/src/gui/folderwatcher_linux.cpp index 9ab9ab854..a5215b3b5 100644 --- a/src/gui/folderwatcher_linux.cpp +++ b/src/gui/folderwatcher_linux.cpp @@ -132,25 +132,25 @@ void FolderWatcherPrivate::slotReceivedNotification(int fd) int error = 0; QVarLengthArray buffer(2048); - do { + len = read(fd, buffer.data(), buffer.size()); + error = errno; + /** + * From inotify documentation: + * + * The behavior when the buffer given to read(2) is too + * small to return information about the next event + * depends on the kernel version: in kernels before 2.6.21, + * read(2) returns 0; since kernel 2.6.21, read(2) fails with + * the error EINVAL. + */ + while (len < 0 && error == EINVAL) { + // double the buffer size + buffer.resize(buffer.size() * 2); + + /* and try again ... */ len = read(fd, buffer.data(), buffer.size()); error = errno; - /** - * From inotify documentation: - * - * The behavior when the buffer given to read(2) is too - * small to return information about the next event - * depends on the kernel version: in kernels before 2.6.21, - * read(2) returns 0; since kernel 2.6.21, read(2) fails with - * the error EINVAL. - */ - if (len < 0 && error == EINVAL) { - // double the buffer size - buffer.resize(buffer.size() * 2); - /* and try again ... */ - continue; - } - } while (false); + } // reset counter i = 0; -- 2.30.2