obmc-console: Fix bugprone-narrowing-conversions
For example:
```
/mnt/host/andrew/home/andrew/src/openbmc/obmc-console/build/../console-server.c:769:9: error: narrowing conversion from 'ssize_t' (aka 'long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors]
rc = read(console->tty_fd, buf, sizeof(buf));
^
```
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I67c158b411f1533ca3b5a62803116e95907e8c5b
diff --git a/socket-handler.c b/socket-handler.c
index b10615b..79e1641 100644
--- a/socket-handler.c
+++ b/socket-handler.c
@@ -19,6 +19,7 @@
#include <assert.h>
#include <err.h>
#include <errno.h>
+#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -112,9 +113,13 @@
static ssize_t send_all(struct client *client, void *buf, size_t len,
bool block)
{
- int fd, rc, flags;
+ int fd, flags;
+ ssize_t rc;
size_t pos;
+ if (len > SSIZE_MAX)
+ return -EINVAL;
+
fd = client->fd;
flags = MSG_NOSIGNAL;
@@ -139,7 +144,7 @@
return -1;
}
- return pos;
+ return (ssize_t)pos;
}
/* Drain the queue to the socket and update the queue buffer. If force_len is
@@ -189,7 +194,8 @@
size_t force_len)
{
struct client *client = arg;
- int rc, len;
+ size_t len;
+ int rc;
len = ringbuffer_len(client->rbc);
if (!force_len && (len < SOCKET_HANDLER_PKT_SIZE)) {
@@ -238,7 +244,7 @@
struct socket_handler *sh = to_socket_handler(handler);
struct client *client = data;
uint8_t buf[4096];
- int rc;
+ ssize_t rc;
if (events & POLLIN) {
rc = recv(client->fd, buf, sizeof(buf), MSG_DONTWAIT);