]> PatchyGit - patchyircd.git/commitdiff
fix a bunch of extra warnings
authorEgor <egor@patchysicp.xyz>
Sun, 15 Jun 2025 06:21:54 +0000 (09:21 +0300)
committerEgor <egor@patchysicp.xyz>
Sun, 15 Jun 2025 06:21:54 +0000 (09:21 +0300)
configure.ac
src/admin.cpp
src/common.hpp
src/crypt_blowfish.cpp
src/irc.cpp
src/main.cpp
src/map.cpp
src/net.cpp
src/passwd.cpp
src/setpass.cpp
src/util.cpp

index 58b6fc2..ca3e2fd 100644 (file)
@@ -15,6 +15,8 @@ AM_SILENT_RULES([yes])
 AC_LANG([C++])
 AC_PROG_CXX
 AX_CXX_COMPILE_STDCXX([20], [noext])
+# TODO: -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes
+# TODO: -Wshorten-64-to-32 -Wimplicit-int-conversion -Wextra-semi-stmt -Wcast-qual
 AX_CHECK_COMPILE_FLAG([-Wmissing-variable-declarations],
                                          [AC_SUBST([WMISSINGVAR], [-Wmissing-variable-declarations])])
 AC_DEFINE([_GNU_SOURCE], [1])
index ff99133..7c24cab 100644 (file)
@@ -495,7 +495,7 @@ int admin_hook(const char *hook, Client *cl1, Client *cl2, Channel *chan, char *
                lua_pop(L, 1);
                return 0;
        }
-       int rv = lua_tointeger(L, 1);
+       int rv = (int)lua_tointeger(L, 1);
        lua_pop(L, 1);
        return rv;
 }
index 00142d9..4e4d541 100644 (file)
@@ -21,6 +21,7 @@
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <sys/time.h>
+#include <sys/types.h>
 #include <sys/wait.h>
 #include <termios.h>
 #include <unistd.h>
index 5c07789..1085865 100644 (file)
@@ -368,13 +368,13 @@ static const unsigned char BF_atoi64[0x60] = {
 };
 
 #define BF_safe_atoi64(dst, src) \
-{ \
+do { \
        tmp = (unsigned char)(src); \
        if ((unsigned int)(tmp -= 0x20) >= 0x60) return -1; \
        tmp = BF_atoi64[tmp]; \
        if (tmp > 63) return -1; \
        (dst) = tmp; \
-}
+} while(0)
 
 static int BF_decode(BF_word *dst, const char *src, int size)
 {
@@ -386,15 +386,15 @@ static int BF_decode(BF_word *dst, const char *src, int size)
        do {
                BF_safe_atoi64(c1, *sptr++);
                BF_safe_atoi64(c2, *sptr++);
-               *dptr++ = (c1 << 2) | ((c2 & 0x30) >> 4);
+               *dptr++ = ((c1 << 2) | ((c2 & 0x30) >> 4)) & 255;
                if (dptr >= end) break;
 
                BF_safe_atoi64(c3, *sptr++);
-               *dptr++ = ((c2 & 0x0F) << 4) | ((c3 & 0x3C) >> 2);
+               *dptr++ = (((c2 & 0x0F) << 4) | ((c3 & 0x3C) >> 2)) & 255;
                if (dptr >= end) break;
 
                BF_safe_atoi64(c4, *sptr++);
-               *dptr++ = ((c3 & 0x03) << 6) | c4;
+               *dptr++ = (((c3 & 0x03) << 6) | c4) & 255;
        } while (dptr < end);
 
        return 0;
@@ -444,6 +444,7 @@ static void BF_swap(BF_word *x, int count)
 }
 
 #define BF_ROUND(L, R, N) \
+do { \
        tmp1 = L & 0xFF; \
        tmp2 = L >> 8; \
        tmp2 &= 0xFF; \
@@ -457,7 +458,8 @@ static void BF_swap(BF_word *x, int count)
        tmp3 ^= tmp2; \
        R ^= ctx->s.P[N + 1]; \
        tmp3 += tmp1; \
-       R ^= tmp3;
+       R ^= tmp3; \
+} while (0)
 
 static BF_word BF_encrypt(BF_ctx *ctx,
     BF_word L, BF_word R,
index c31c30a..c32f144 100644 (file)
@@ -398,9 +398,9 @@ int irc_process_line(Client *client, char *source, char *command, int argc, char
                                        }
                                        p = q = (unsigned char *)client->saslbuf;
                                        for (size_t i = 0; i < client->saslbufLen; i += 4) {
-                                               *q++ = p[0]<<2 | p[1]>>4;
-                                               *q++ = p[1]<<4 | p[2]>>2;
-                                               *q++ = p[2]<<6 | p[3];
+                                               *q++ = (p[0]<<2 | p[1]>>4) & 255;
+                                               *q++ = (p[1]<<4 | p[2]>>2) & 255;
+                                               *q++ = (p[2]<<6 | p[3]) & 255;
                                                p += 4;
                                        }
                                        client->saslbufLen = q-(unsigned char *)client->saslbuf - parity;
@@ -504,7 +504,7 @@ saslcleanup:
                        else
                                client->webircwait = 2;
                        if (!strcmp(args[1], "biboumi")) {
-                               int len = strlen(args[2]);
+                               size_t len = strlen(args[2]);
                                client->webirchostname = (char *)malloc(len+sizeof(".xmpp"));
                                if (client->webirchostname) {
                                        memcpy(client->webirchostname, args[2], len);
@@ -1021,7 +1021,7 @@ saslcleanup:
                        if (cl)
                                *p++ = cl;
                }
-               rpl_userhost(client, cls, p - cls);
+               rpl_userhost(client, cls, (int)(p - cls));
                sendbuf(client);
        // User-Based Queries
        } else if(strcmp(command, "WHO") == 0) {
@@ -1133,7 +1133,7 @@ saslcleanup:
                        if (strchr(args[1], ' '))
                                return err_needmoreparams(client, command), sendbuf(client), 0; /* FIXME: wrong error */
                        stringlower(args[1]);
-                       int monitor_count = client->monitor.size();
+                       size_t monitor_count = client->monitor.size();
                        char *p = args[1];
                        do {
                                char *nick = p;
@@ -1264,7 +1264,7 @@ void sendLUSERS(Client *client)
        int registered = 0;
        int invisible = 0;
        int ops = 0;
-       int channels = channel_map.size();
+       int channels = (int)channel_map.size();
        for (auto cl : client_map) {
                registered++;
                if (cl->umode & UMODE_INVISIBLE)
@@ -1803,7 +1803,7 @@ void channel_topic(Client *src, Channel *chan, const char *topic, const char *wh
 Client *findClient(const char *nickname)
 {
        char key[MAX_NICKLEN];
-       int len = strlen(nickname);
+       size_t len = strlen(nickname);
        if (len >= MAX_NICKLEN)
                return NULL;
        memcpy(key, nickname, len+1);
index 7cb6e89..acab933 100644 (file)
@@ -110,7 +110,7 @@ static void accept_from_sock(struct listener *listener)
                }
 
                char client_addr[100];
-               int port;
+               unsigned short port;
                int is_local = 0;
                if (addr.ss_family == AF_INET) {
                        struct in_addr *ia = &((struct sockaddr_in *)&addr)->sin_addr;
@@ -302,7 +302,7 @@ int main(int argc, char *argv[])
                irc_parse_line(fake, fake->rbuf, 0);
                while (fgets(fake->rbuf, sizeof(fake->rbuf), f)) {
                        char *p = fake->rbuf;
-                       int len = strlen(fake->rbuf);
+                       size_t len = strlen(fake->rbuf);
                        if (!len || fake->rbuf[len-1] != '\n')
                                break;
                        unsigned long faketime;
@@ -318,7 +318,7 @@ int main(int argc, char *argv[])
                                char *sp = strchr(p, ' ');
                                char *bang = strchr(p, '!');
                                if (sp && bang && bang < sp) {
-                                       int nlen = bang - p - 1;
+                                       size_t nlen = bang - p - 1;
                                        if (memcmp(&p[1], fake->nick, nlen) != 0) {
                                                char *nnick = (char *)malloc(nlen+1);
                                                if (!nnick)
index 7b596bf..5455828 100644 (file)
@@ -3,7 +3,7 @@
 #include "common.hpp"
 #include "map.hpp"
 #include "ircdata.hpp"
-static int ent_find(map_base *root, const char *key, int *found)
+static size_t ent_find(map_base *root, const char *key, int *found)
 {
        auto it = std::partition_point(root->ptr, root->ptr + root->len,
                        [key](const auto &p){ return strcmp(p.key, key) < 0; });
@@ -13,13 +13,13 @@ static int ent_find(map_base *root, const char *key, int *found)
 void *map_base::_get(const char *key)
 {
        int found;
-       int i = ent_find(this, key, &found);
+       size_t i = ent_find(this, key, &found);
        return found ? ptr[i].value : 0;
 }
 int map_base::_set(const char *key, const void *value, void **oldvalue)
 {
        int found;
-       int i = ent_find(this, key, &found);
+       size_t i = ent_find(this, key, &found);
        if (found) {
                if (oldvalue)
                        *oldvalue = ptr[i].value;
@@ -28,21 +28,21 @@ int map_base::_set(const char *key, const void *value, void **oldvalue)
                        std::copy(ptr+i+1, ptr+len, ptr+i);
                        len--;
                } else {
-                       ptr[i].value = (void *)value;
+                       ptr[i].value = const_cast<void *>(value);
                }
        } else {
                if (oldvalue)
                        *oldvalue = 0;
                if (value) {
                        if (len == cap) {
-                               int ncap = cap ? cap*2 : 2;
+                               size_t ncap = cap ? cap*2 : 2;
                                map_value *nptr = (map_value *)realloc(ptr, sizeof(map_value)*ncap);
                                if (!nptr)
                                        return -1;
                                ptr = nptr;
                                cap = ncap;
                        }
-                       int slen = strlen(key)+1;
+                       size_t slen = strlen(key)+1;
                        char *nkey = (char *)malloc(slen);
                        if (!nkey)
                                return -1;
@@ -50,7 +50,7 @@ int map_base::_set(const char *key, const void *value, void **oldvalue)
                        std::copy_backward(ptr+i, ptr+len, ptr+len+1);
                        len++;
                        ptr[i].key = nkey;
-                       ptr[i].value = (void *)value;
+                       ptr[i].value = const_cast<void *>(value);
                }
        }
        return 0;
index 97554f0..8bed8d2 100644 (file)
@@ -215,7 +215,7 @@ void read_proc(Client *cl)
 
 /* returns the count of bytes which were not sent, or -1 on error.
  * updates want_read_for_write and want_write_for_write */
-static int sendClientRaw(Client *cl, const char *buf, size_t len)
+static ssize_t sendClientRaw(Client *cl, const char *buf, size_t len)
 {
        cl->want_read_for_write = 0;
        cl->want_write_for_write = 0;
@@ -224,7 +224,7 @@ static int sendClientRaw(Client *cl, const char *buf, size_t len)
 #ifdef HAVE_LIBTLS
        if (cl->cctx) {
                while (len) {
-                       int rv = tls_write(cl->cctx, buf, len);
+                       ssize_t rv = tls_write(cl->cctx, buf, len);
                        if (rv == 0 || rv == -1) {
                                return -1;
                        } else if (rv == TLS_WANT_POLLIN) {
@@ -241,7 +241,7 @@ static int sendClientRaw(Client *cl, const char *buf, size_t len)
 #endif
        {
                while (len) {
-                       int rv = send(cl->fd, buf, len, 0);
+                       ssize_t rv = send(cl->fd, buf, len, 0);
                        if (!rv)
                                return -1;
                        if (rv == -1) {
@@ -271,7 +271,7 @@ void sendClient(Client *cl, const char *buf, size_t len)
        }
        if (!cl->wlen) {
                if (len) {
-                       int left = sendClientRaw(cl, buf, len);
+                       ssize_t left = sendClientRaw(cl, buf, len);
                        update_poll_reg(cl);
                        if (left == -1) {
                                /* Write error happened, discard the buffer and close the
@@ -295,7 +295,7 @@ void sendClient(Client *cl, const char *buf, size_t len)
                memcpy(cl->wbuf + cl->wlen, buf, len);
                cl->wlen += len;
        }
-       int left = sendClientRaw(cl, cl->wbuf, cl->wlen);
+       ssize_t left = sendClientRaw(cl, cl->wbuf, cl->wlen);
        update_poll_reg(cl);
        if (left == -1) {
                cl->wlen = 0;
index 65bdce0..b67a9c1 100644 (file)
@@ -22,7 +22,7 @@ char *password_hash2(const char *pw, int algo, int strength)
        char salt[7 + 22 + 1]; // 20 for SHA512
        if (algo == 2) {
                memcpy(salt, "$2b$10$", 7);
-               salt[5] = strength - 10 + '0';
+               salt[5] = (strength - 10 + '0') & 255;
                for (int i = 0; i < 5; i++) {
                        salt[ 7+4*i] = b64[ubytes[0+3*i]>>2];
                        salt[ 8+4*i] = b64[(ubytes[0+3*i]<<4 & 63) | ubytes[1+3*i]>>4];
@@ -55,7 +55,7 @@ int password_set(const char *key, const char *pw, const char *fn, const char *tm
                return -1;
        }
 
-       int keylen = strlen(key);
+       size_t keylen = strlen(key);
        char buf[1024];
        while (fgets(buf, 1024, fi)) {
                if (buf[keylen] != ':' || memcmp(buf, key, keylen) != 0) {
@@ -97,11 +97,11 @@ char *password_get(const char *key, const char *fn)
        FILE *fi = fopen(fn, "rbe");
        if (!fi)
                return 0;
-       int keylen = strlen(key);
+       size_t keylen = strlen(key);
        static char buf[1024];
        while (fgets(buf, 1024, fi)) {
                if (buf[keylen] == ':' && memcmp(buf, key, keylen) == 0) {
-                       int len = strlen(buf);
+                       size_t len = strlen(buf);
                        if (buf[len-1] == '\n')
                                buf[len-1] = '\0';
                        fclose(fi);
@@ -131,13 +131,13 @@ const char *db_read_rhs(const char *key, const char *fn) {
        FILE *fi = fopen(fn, "rbe");
        if (!fi)
                return 0;
-       int keylen = strlen(key);
+       size_t keylen = strlen(key);
        static char buf[1024];
        while (fgets(buf, 1024, fi)) {
                char *rhs = strchr(buf, ':');
                if (rhs) {
                        rhs++;
-                       int len = strlen(rhs);
+                       size_t len = strlen(rhs);
                        if (rhs[len-1] == '\n')
                                rhs[--len] = '\0';
                        if (keylen == len && memcmp(rhs, key, keylen) == 0) {
index c86d306..819ace6 100644 (file)
@@ -3,7 +3,7 @@
 #include "common.hpp"
 #include "passwd.hpp"
 
-char *read_password(const char *prompt)
+static char *read_password(const char *prompt)
 {
        static char buffer[256];
        struct termios oldattr, newattr;
index 011bafc..4266fbd 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 #include "common.hpp"
 #include "util.hpp"
-static void append_strn(std::vector<char> *v, const char *s, int len) {
+static void append_strn(std::vector<char> *v, const char *s, size_t len) {
        v->insert(v->end(), s, s+len);
 }
 void append_str(std::vector<char> *v, const char *s) {
@@ -16,7 +16,7 @@ void append_strf(std::vector<char> *v, const char *s, ...) {
                const char *end = strchr(s, '%');
                if (!end) {
                        // if format string ends with \n, append \r\n
-                       int len = strlen(s);
+                       size_t len = strlen(s);
                        if (len) {
                                if (s[len-1] == '\n' && (len == 1 || s[len-2] != '\r')) {
                                        append_strn(v, s, len-1);
@@ -69,7 +69,7 @@ void stringlower(char *s) {
        }
 }
 char *mystrdup(const char *s) {
-       int len = strlen(s);
+       size_t len = strlen(s);
        char *buf = (char *)malloc(len+1);
        if (buf)
                memcpy(buf, s, len+1);