Skip to content

Commit

Permalink
Fixed conversion warnings on framework tests (#2606)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Michael D Starch <Michael.D.Starch@jpl.nasa.gov>
  • Loading branch information
JohanBertrand and LeStarch authored Apr 30, 2024
1 parent 0d4e909 commit d518121
Show file tree
Hide file tree
Showing 96 changed files with 615 additions and 394 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ subgrouping
subhist
subhistory
subpage
suseconds
subseconds
subtargets
suppr
Expand Down
2 changes: 1 addition & 1 deletion CFDP/Checksum/Checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace CFDP {
)
{
FW_ASSERT(offset < 4);
const U32 addend = byte << (8*(3-offset));
const U32 addend = static_cast<U32>(byte) << (8*(3-offset));
this->m_value += addend;
}

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ if (NOT BUILD_TESTING)
add_compile_options(
-Wshadow
-pedantic
-Wconversion
)
endif()

Expand Down
19 changes: 10 additions & 9 deletions Drv/Ip/IpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ IpSocket::IpSocket() : m_fd(-1), m_timeoutSeconds(0), m_timeoutMicroseconds(0),
}

SocketIpStatus IpSocket::configure(const char* const hostname, const U16 port, const U32 timeout_seconds, const U32 timeout_microseconds) {
FW_ASSERT(timeout_microseconds < 1000000, timeout_microseconds);
FW_ASSERT(timeout_microseconds < 1000000, static_cast<FwAssertArgType>(timeout_microseconds));
FW_ASSERT(port != 0, port);
this->m_timeoutSeconds = timeout_seconds;
this->m_timeoutMicroseconds = timeout_microseconds;
Expand All @@ -67,8 +67,8 @@ SocketIpStatus IpSocket::setupTimeouts(NATIVE_INT_TYPE socketFd) {
#else
// Set timeout socket option
struct timeval timeout;
timeout.tv_sec = this->m_timeoutSeconds;
timeout.tv_usec = this->m_timeoutMicroseconds;
timeout.tv_sec = static_cast<time_t>(this->m_timeoutSeconds);
timeout.tv_usec = static_cast<suseconds_t>(this->m_timeoutMicroseconds);
// set socket write to timeout after 1 sec
if (setsockopt(socketFd, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<char *>(&timeout), sizeof(timeout)) < 0) {
return SOCK_FAILED_TO_SET_SOCKET_OPTIONS;
Expand Down Expand Up @@ -182,17 +182,18 @@ SocketIpStatus IpSocket::send(const U8* const data, const U32 size) {
return SOCK_SEND_ERROR;
}
FW_ASSERT(sent > 0, sent);
total += sent;
total += static_cast<U32>(sent);
}
// Failed to retry enough to send all data
if (total < size) {
return SOCK_INTERRUPTED_TRY_AGAIN;
}
FW_ASSERT(total == size, total, size); // Ensure we sent everything
// Ensure we sent everything
FW_ASSERT(total == size, static_cast<FwAssertArgType>(total), static_cast<FwAssertArgType>(size));
return SOCK_SUCCESS;
}

SocketIpStatus IpSocket::recv(U8* data, I32& req_read) {
SocketIpStatus IpSocket::recv(U8* data, U32& req_read) {
I32 size = 0;
// Check for previously disconnected socket
if (m_fd == -1) {
Expand All @@ -210,16 +211,16 @@ SocketIpStatus IpSocket::recv(U8* data, I32& req_read) {
// Zero bytes read reset or bad ef means we've disconnected
else if (size == 0 || ((size == -1) && ((errno == ECONNRESET) || (errno == EBADF)))) {
this->close();
req_read = size;
req_read = static_cast<U32>(size);
return SOCK_DISCONNECTED;
}
// Error returned, and it wasn't an interrupt, nor a disconnect
else if (size == -1) {
req_read = size;
req_read = static_cast<U32>(size);
return SOCK_READ_ERROR; // Stop recv task on error
}
}
req_read = size;
req_read = static_cast<U32>(size);
// Prevent interrupted socket being viewed as success
if (size == -1) {
return SOCK_INTERRUPTED_TRY_AGAIN;
Expand Down
2 changes: 1 addition & 1 deletion Drv/Ip/IpSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class IpSocket {
* \param size: maximum size of data buffer to fill
* \return status of the send, SOCK_DISCONNECTED to reopen, SOCK_SUCCESS on success, something else on error
*/
SocketIpStatus recv(U8* const data, I32& size);
SocketIpStatus recv(U8* const data, U32& size);
/**
* \brief closes the socket
*
Expand Down
17 changes: 12 additions & 5 deletions Drv/Ip/SocketReadTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ void SocketReadTask::readTask(void* pointer) {
// Open a network connection if it has not already been open
if ((not self->getSocketHandler().isStarted()) and (not self->m_stop) and
((status = self->startup()) != SOCK_SUCCESS)) {
Fw::Logger::logMsg("[WARNING] Failed to open port with status %d and errno %d\n", status, errno);
Fw::Logger::logMsg(
"[WARNING] Failed to open port with status %d and errno %d\n",
static_cast<POINTER_CAST>(status),
static_cast<POINTER_CAST>(errno));
(void) Os::Task::delay(SOCKET_RETRY_INTERVAL_MS);
continue;
}

// Open a network connection if it has not already been open
if ((not self->getSocketHandler().isOpened()) and (not self->m_stop) and
((status = self->open()) != SOCK_SUCCESS)) {
Fw::Logger::logMsg("[WARNING] Failed to open port with status %d and errno %d\n", status, errno);
Fw::Logger::logMsg(
"[WARNING] Failed to open port with status %d and errno %d\n",
static_cast<POINTER_CAST>(status),
static_cast<POINTER_CAST>(errno));
(void) Os::Task::delay(SOCKET_RETRY_INTERVAL_MS);
continue;
}
Expand All @@ -92,11 +98,12 @@ void SocketReadTask::readTask(void* pointer) {
Fw::Buffer buffer = self->getBuffer();
U8* data = buffer.getData();
FW_ASSERT(data);
I32 size = static_cast<I32>(buffer.getSize());
size = (size >= 0) ? size : MAXIMUM_SIZE; // Handle max U32 edge case
U32 size = buffer.getSize();
status = self->getSocketHandler().recv(data, size);
if ((status != SOCK_SUCCESS) && (status != SOCK_INTERRUPTED_TRY_AGAIN)) {
Fw::Logger::logMsg("[WARNING] Failed to recv from port with status %d and errno %d\n", status, errno);
Fw::Logger::logMsg("[WARNING] Failed to recv from port with status %d and errno %d\n",
static_cast<POINTER_CAST>(status),
static_cast<POINTER_CAST>(errno));
self->getSocketHandler().close();
buffer.setSize(0);
} else {
Expand Down
4 changes: 2 additions & 2 deletions Drv/Ip/TcpClientSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ SocketIpStatus TcpClientSocket::openProtocol(NATIVE_INT_TYPE& fd) {
}

I32 TcpClientSocket::sendProtocol(const U8* const data, const U32 size) {
return ::send(this->m_fd, data, size, SOCKET_IP_SEND_FLAGS);
return static_cast<I32>(::send(this->m_fd, data, size, SOCKET_IP_SEND_FLAGS));
}

I32 TcpClientSocket::recvProtocol(U8* const data, const U32 size) {
return ::recv(this->m_fd, data, size, SOCKET_IP_RECV_FLAGS);
return static_cast<I32>(::recv(this->m_fd, data, size, SOCKET_IP_RECV_FLAGS));
}

} // namespace Drv
4 changes: 2 additions & 2 deletions Drv/Ip/TcpServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ SocketIpStatus TcpServerSocket::openProtocol(NATIVE_INT_TYPE& fd) {
}

I32 TcpServerSocket::sendProtocol(const U8* const data, const U32 size) {
return ::send(this->m_fd, data, size, SOCKET_IP_SEND_FLAGS);
return static_cast<I32>(::send(this->m_fd, data, size, SOCKET_IP_SEND_FLAGS));
}

I32 TcpServerSocket::recvProtocol(U8* const data, const U32 size) {
return ::recv(this->m_fd, data, size, SOCKET_IP_RECV_FLAGS);
return static_cast<I32>(::recv(this->m_fd, data, size, SOCKET_IP_RECV_FLAGS));
}

} // namespace Drv
6 changes: 3 additions & 3 deletions Drv/Ip/UdpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ SocketIpStatus UdpSocket::openProtocol(NATIVE_INT_TYPE& fd) {

I32 UdpSocket::sendProtocol(const U8* const data, const U32 size) {
FW_ASSERT(this->m_state->m_addr_send.sin_family != 0); // Make sure the address was previously setup
return ::sendto(this->m_fd, data, size, SOCKET_IP_SEND_FLAGS,
reinterpret_cast<struct sockaddr *>(&this->m_state->m_addr_send), sizeof(this->m_state->m_addr_send));
return static_cast<I32>(::sendto(this->m_fd, data, size, SOCKET_IP_SEND_FLAGS,
reinterpret_cast<struct sockaddr *>(&this->m_state->m_addr_send), sizeof(this->m_state->m_addr_send)));
}

I32 UdpSocket::recvProtocol(U8* const data, const U32 size) {
FW_ASSERT(this->m_state->m_addr_recv.sin_family != 0); // Make sure the address was previously setup
return ::recvfrom(this->m_fd, data, size, SOCKET_IP_RECV_FLAGS, nullptr, nullptr);
return static_cast<I32>(::recvfrom(this->m_fd, data, size, SOCKET_IP_RECV_FLAGS, nullptr, nullptr));
}

} // namespace Drv
4 changes: 2 additions & 2 deletions Drv/Ip/test/ut/SocketTestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ void fill_random_buffer(Fw::Buffer &buffer) {
}

void send_recv(Drv::IpSocket& sender, Drv::IpSocket& receiver) {
I32 size = MAX_DRV_TEST_MESSAGE_SIZE;
U32 size = MAX_DRV_TEST_MESSAGE_SIZE;
U8 buffer_out[MAX_DRV_TEST_MESSAGE_SIZE] = {0};
U8 buffer_in[MAX_DRV_TEST_MESSAGE_SIZE] = {0};

// Send receive validate block
Drv::Test::fill_random_data(buffer_out, MAX_DRV_TEST_MESSAGE_SIZE);
EXPECT_EQ(sender.send(buffer_out, MAX_DRV_TEST_MESSAGE_SIZE), Drv::SOCK_SUCCESS);
EXPECT_EQ(receiver.recv(buffer_in, size), Drv::SOCK_SUCCESS);
EXPECT_EQ(size, static_cast<I32>(MAX_DRV_TEST_MESSAGE_SIZE));
EXPECT_EQ(size, static_cast<U32>(MAX_DRV_TEST_MESSAGE_SIZE));
Drv::Test::validate_random_data(buffer_out, buffer_in, MAX_DRV_TEST_MESSAGE_SIZE);
}

Expand Down
28 changes: 14 additions & 14 deletions Drv/LinuxGpioDriver/LinuxGpioDriverComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Drv {

// TODO check value of len
len = snprintf(buf, sizeof(buf), "%u", gpio);
if(write(fd, buf, len) != len) {
if(write(fd, buf, static_cast<size_t>(len)) != len) {
(void) close(fd);
DEBUG_PRINT("gpio/export error!\n");
return -1;
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace Drv {

// TODO check value of len
len = snprintf(buf, sizeof(buf), "%u", gpio);
if(write(fd, buf, len) != len) {
if(write(fd, buf, static_cast<size_t>(len)) != len) {
(void) close(fd);
DEBUG_PRINT("gpio/unexport error!\n");
return -1;
Expand Down Expand Up @@ -114,9 +114,9 @@ namespace Drv {
}

const char *dir = out_flag ? "out" : "in";
len = strlen(dir);
len = static_cast<int>(strlen(dir));

if (write(fd, dir, len) != len) {
if (write(fd, dir, static_cast<size_t>(len)) != len) {
(void) close(fd);
DEBUG_PRINT("gpio/direction error!\n");
return -1;
Expand Down Expand Up @@ -157,8 +157,8 @@ namespace Drv {

FW_ASSERT(fd != -1);

NATIVE_INT_TYPE stat1 = lseek(fd, 0, SEEK_SET); // Must seek back to the starting
NATIVE_INT_TYPE stat2 = read(fd, &ch, 1);
NATIVE_INT_TYPE stat1 = static_cast<NATIVE_INT_TYPE>(lseek(fd, 0, SEEK_SET)); // Must seek back to the starting
NATIVE_INT_TYPE stat2 = static_cast<NATIVE_INT_TYPE>(read(fd, &ch, 1));

if (stat1 == -1 || stat2 != 1) {
DEBUG_PRINT("GPIO read failure: %d %d!\n",stat1,stat2);
Expand Down Expand Up @@ -199,8 +199,8 @@ namespace Drv {
return -1;
}

len = strlen(edge) + 1;
if(write(fd, edge, len) != len) {
len = static_cast<int>(strlen(edge) + 1);
if(write(fd, edge, static_cast<size_t>(len)) != len) {
(void) close(fd);
DEBUG_PRINT("gpio/set-edge error!\n");
return -1;
Expand Down Expand Up @@ -292,13 +292,13 @@ namespace Drv {
NATIVE_INT_TYPE stat;

// Configure:
stat = gpio_export(gpio);
stat = gpio_export(static_cast<unsigned int>(gpio));
if (-1 == stat) {
Fw::LogStringArg arg = strerror(errno);
this->log_WARNING_HI_GP_OpenError(gpio,stat,arg);
return false;
}
stat = gpio_set_dir(gpio, direction == GPIO_OUT ? 1 : 0);
stat = gpio_set_dir(static_cast<unsigned int>(gpio), direction == GPIO_OUT ? 1 : 0);
if (-1 == stat) {
Fw::LogStringArg arg = strerror(errno);
this->log_WARNING_HI_GP_OpenError(gpio,stat,arg);
Expand All @@ -308,7 +308,7 @@ namespace Drv {
// If needed, set edge to rising in intTaskEntry()

// Open:
this->m_fd = gpio_fd_open(gpio);
this->m_fd = gpio_fd_open(static_cast<unsigned int>(gpio));
if (-1 == this->m_fd) {
Fw::LogStringArg arg = strerror(errno);
this->log_WARNING_HI_GP_OpenError(gpio,errno,arg);
Expand All @@ -330,7 +330,7 @@ namespace Drv {

// start GPIO interrupt
NATIVE_INT_TYPE stat;
stat = gpio_set_edge(compPtr->m_gpio, "rising");
stat = gpio_set_edge(static_cast<unsigned int>(compPtr->m_gpio), "rising");
if (-1 == stat) {
compPtr->log_WARNING_HI_GP_IntStartError(compPtr->m_gpio);
return;
Expand All @@ -346,7 +346,7 @@ namespace Drv {

fdset[0].fd = compPtr->m_fd;
fdset[0].events = POLLPRI;
stat = poll(fdset, nfds, timeout);
stat = poll(fdset, static_cast<nfds_t>(nfds), timeout);

/*
* According to this link, poll will always have POLLERR set for the sys/class/gpio subsystem
Expand Down Expand Up @@ -422,7 +422,7 @@ namespace Drv {
{
if (this->m_fd != -1) {
DEBUG_PRINT("Closing GPIO %d fd %d\n",this->m_gpio, this->m_fd);
(void) gpio_fd_close(this->m_fd, this->m_gpio);
(void) gpio_fd_close(this->m_fd, static_cast<unsigned int>(this->m_gpio));
}

}
Expand Down
4 changes: 2 additions & 2 deletions Drv/LinuxI2cDriver/LinuxI2cDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace Drv {
// make sure it isn't a null pointer
FW_ASSERT(serBuffer.getData());
// write data
stat = write(this->m_fd, serBuffer.getData(), serBuffer.getSize());
stat = static_cast<int>(write(this->m_fd, serBuffer.getData(), serBuffer.getSize()));
if (stat == -1) {
#if DEBUG_PRINT
Fw::Logger::logMsg("Status: %d Errno: %d\n", stat, errno);
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace Drv {
// make sure it isn't a null pointer
FW_ASSERT(serBuffer.getData());
// read data
stat = read(this->m_fd, serBuffer.getData(), serBuffer.getSize());
stat = static_cast<int>(read(this->m_fd, serBuffer.getData(), serBuffer.getSize()));
if (stat == -1) {
#if DEBUG_PRINT
Fw::Logger::logMsg("Status: %d Errno: %d\n", stat, errno);
Expand Down
Loading

0 comments on commit d518121

Please sign in to comment.