[Replicant] [libsamsung-ipc][ 1/6] ipc.c: fix integer comparison sign

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Fri Feb 21 00:12:38 UTC 2020


With:
    ./configure CC=clang CFLAGS=-W -Wall -Wno-unused \
                --no-create --no-recursion
we have:
    CC       ipc.lo
    ipc.c:71:16: warning: comparison of integers of
    different signs: 'size_t' (aka 'unsigned int') and
    'int' [-Wsign-compare]
    if (length == -1)
        ~~~~~~ ^  ~~

This is caused by the following code:
    size_t length;
    [...]
    length = read(fd, &buffer, sizeof(buffer));
    if (length == -1)
        goto error;

However, as per the function definition, read uses ssize_t
which is the signed version of size_t:
    ssize_t read(int fd, void *buf, size_t count);

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
 samsung-ipc/ipc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c
index 50b6980..2aaaff6 100644
--- a/samsung-ipc/ipc.c
+++ b/samsung-ipc/ipc.c
@@ -51,7 +51,7 @@ int ipc_device_detect(void)
     char *line, *p, *c;
     int index = -1;
     int fd = -1;
-    size_t length;
+    ssize_t length;
     int i;
 
 #ifdef IPC_DEVICE_NAME
-- 
2.25.0



More information about the Replicant mailing list