Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinuxGpioDriver: fix static_assert's for FwSizeType. Possible fix for #3030 #3118

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Drv/LinuxGpioDriver/LinuxGpioDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <cerrno>
#include <type_traits>

namespace Drv {

Expand Down Expand Up @@ -287,9 +288,13 @@ Drv::GpioStatus LinuxGpioDriver ::gpioWrite_handler(const NATIVE_INT_TYPE portNu
}

void LinuxGpioDriver ::pollLoop() {
static_assert(GPIO_POLL_TIMEOUT < std::numeric_limits<int>::max(), "Poll timeout would overflow");
// Ensure size of FwSizeType is large enough to fit the necessary ranges
// NOTE: casts to unsigned types for int and ssize_t are made to avoid sign-compare warning;
// in both cases the cast is safe because max() returns nonnegative value.
static_assert(GPIO_POLL_TIMEOUT < static_cast<unsigned int>(std::numeric_limits<int>::max()), "Poll timeout would overflow");
static_assert(sizeof(struct gpioevent_data) < std::numeric_limits<FwSizeType>::max(), "FwSizeType too small");
static_assert(std::numeric_limits<ssize_t>::max() <= std::numeric_limits<FwSizeType>::max(), "FwSizeType too small");
typedef std::make_unsigned<ssize_t>::type unsigned_ssize_t;
static_assert(static_cast<unsigned_ssize_t>(std::numeric_limits<ssize_t>::max()) <= std::numeric_limits<FwSizeType>::max(), "FwSizeType too small");
// Setup poll information
pollfd file_descriptors[1];
// Loop forever
Expand Down
Loading