From 2088adcdc1c458557c060e345bf12ef298b92ea5 Mon Sep 17 00:00:00 2001 From: Wirtos_new Date: Thu, 17 Jun 2021 14:16:09 +0300 Subject: [PATCH] explicitly cast -1 to size_t, support static_assert on pre-c11 --- app/src/cli.c | 4 ++++ app/src/receiver.c | 6 +++--- app/src/stream.c | 2 +- app/src/sys/unix/command.c | 2 +- app/src/util/net.c | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/cli.c b/app/src/cli.c index a6fa3c71..ab6a72f1 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -10,6 +10,10 @@ #include "util/log.h" #include "util/str_util.h" +#ifndef static_assert + #define static_assert(x, msg) (void) sizeof(struct {int a[(x) ? 1 : -1]}) +#endif + void scrcpy_print_usage(const char *arg0) { fprintf(stderr, diff --git a/app/src/receiver.c b/app/src/receiver.c index 085026e7..cf0f9a13 100644 --- a/app/src/receiver.c +++ b/app/src/receiver.c @@ -47,7 +47,7 @@ process_msgs(const unsigned char *buf, size_t len) { for (;;) { struct device_msg msg; size_t r = device_msg_deserialize(&buf[head], len - head, &msg); - if (r == -1) { + if (r == (size_t)-1) { return -1; } if (r == 0) { @@ -76,14 +76,14 @@ run_receiver(void *data) { assert(head < DEVICE_MSG_MAX_SIZE); size_t r = net_recv(receiver->control_socket, buf + head, DEVICE_MSG_MAX_SIZE - head); - if (!r || r == -1) { + if (!r || r == (size_t)-1) { LOGD("Receiver stopped"); break; } head += r; size_t consumed = process_msgs(buf, head); - if (consumed == -1) { + if (consumed == (size_t)-1) { // an error occurred break; } diff --git a/app/src/stream.c b/app/src/stream.c index f8dedb8a..3e874fb5 100644 --- a/app/src/stream.c +++ b/app/src/stream.c @@ -51,7 +51,7 @@ stream_recv_packet(struct stream *stream, AVPacket *packet) { } r = net_recv_all(stream->socket, packet->data, len); - if (r == -1 || ((uint32_t) r) < len) { + if (r == (size_t)-1 || ((uint32_t) r) < len) { av_packet_unref(packet); return false; } diff --git a/app/src/sys/unix/command.c b/app/src/sys/unix/command.c index 1241ce06..0b291f72 100644 --- a/app/src/sys/unix/command.c +++ b/app/src/sys/unix/command.c @@ -156,7 +156,7 @@ get_executable_path(void) { #ifdef __linux__ char buf[PATH_MAX + 1]; // +1 for the null byte size_t len = readlink("/proc/self/exe", buf, PATH_MAX); - if (len == -1) { + if (len == (size_t)-1) { perror("readlink"); return NULL; } diff --git a/app/src/util/net.c b/app/src/util/net.c index c71c6362..08348cdd 100644 --- a/app/src/util/net.c +++ b/app/src/util/net.c @@ -103,7 +103,7 @@ net_send_all(socket_t socket, const void *buf, size_t len) { size_t w = 0; while (len > 0) { w = send(socket, buf, len, 0); - if (w == -1) { + if (w == (size_t)-1) { return -1; } len -= w;