]> PatchyGit - patchyircd.git/commitdiff
fix -fpermissive and other c++ errors
authorEgor <egor@patchysicp.xyz>
Tue, 21 Jan 2025 04:07:06 +0000 (06:07 +0200)
committerEgor <egor@patchysicp.xyz>
Tue, 21 Jan 2025 04:07:06 +0000 (06:07 +0200)
.gitignore
src/admin.c
src/irc.c
src/main.c
src/net.c
src/netpoll.c
src/util.c

index 6f53a9c..b5938c1 100644 (file)
@@ -1,4 +1,5 @@
 ircd
+ircd-cxx
 ircd.exe
 setpass
 config.mk
index fc49f3e..46eb974 100644 (file)
@@ -23,11 +23,11 @@ static int map_index(lua_State *L)
                lua_pushvalue(L, 2);
                return 1;
        case MAPTYPE_CLIENT:
-               *(struct client_data **)lua_newuserdatauv(L, sizeof(struct client_data *), 0) = value;
+               *(struct client_data **)lua_newuserdatauv(L, sizeof(struct client_data *), 0) = (struct client_data *)value;
                luaL_setmetatable(L, "client");
                return 1;
        case MAPTYPE_CHANNEL:
-               *(struct channel **)lua_newuserdatauv(L, sizeof(struct channel *), 0) = value;
+               *(struct channel **)lua_newuserdatauv(L, sizeof(struct channel *), 0) = (struct channel *)value;
                luaL_setmetatable(L, "channel");
                return 1;
        }
@@ -49,12 +49,12 @@ static int map_newindex(lua_State *L)
                (void)map_set(m, key, key, 0);
                break;
        case MAPTYPE_CLIENT: {
-               void **p = luaL_checkudata(L, 3, "client");
+               void **p = (void **)luaL_checkudata(L, 3, "client");
                (void)map_set(m, key, *p, 0);
                break;
        }
        case MAPTYPE_CHANNEL: {
-               void **p = luaL_checkudata(L, 3, "channel");
+               void **p = (void **)luaL_checkudata(L, 3, "channel");
                (void)map_set(m, key, *p, 0);
                break;
        }
@@ -63,9 +63,9 @@ static int map_newindex(lua_State *L)
 }
 static int map_iter_next(lua_State *L)
 {
-       map_iter_t *it = luaL_checkudata(L, 1, "map_iter");
+       map_iter_t *it = (map_iter_t *)luaL_checkudata(L, 1, "map_iter");
        lua_getiuservalue(L, 1, 2);
-       const char *key = lua_touserdata(L, -1);
+       const char *key = (const char *)lua_touserdata(L, -1);
        lua_pop(L, 1);
        void *value;
        if (!map_foriter(it, &key, &value))
@@ -80,12 +80,12 @@ static int map_iter_next(lua_State *L)
                return 2;
        case MAPTYPE_CLIENT:
                lua_pushstring(L, key);
-               *(struct client_data **)lua_newuserdatauv(L, sizeof(struct client_data *), 0) = value;
+               *(struct client_data **)lua_newuserdatauv(L, sizeof(struct client_data *), 0) = (struct client_data *)value;
                luaL_setmetatable(L, "client");
                return 2;
        case MAPTYPE_CHANNEL:
                lua_pushstring(L, key);
-               *(struct channel **)lua_newuserdatauv(L, sizeof(struct channel *), 0) = value;
+               *(struct channel **)lua_newuserdatauv(L, sizeof(struct channel *), 0) = (struct channel *)value;
                luaL_setmetatable(L, "channel");
                return 2;
        }
@@ -95,7 +95,7 @@ static int map_pairs(lua_State *L)
 {
        map_t *m = *(map_t **)luaL_checkudata(L, 1, "map");
        lua_pushcfunction(L, map_iter_next);
-       map_iter_t *it = lua_newuserdatauv(L, sizeof(map_iter_t), 2);
+       map_iter_t *it = (map_iter_t *)lua_newuserdatauv(L, sizeof(map_iter_t), 2);
        memset(it, 0, sizeof(*it));
        it->root = m;
        luaL_setmetatable(L, "map_iter");
@@ -279,7 +279,7 @@ static int fn_channel_new(lua_State *L)
        char key[33];
        memcpy(key, channel, chanlen+1);
        stringlower(key);
-       struct channel *chan = map_get(&channel_map, key);
+       struct channel *chan = (struct channel *)map_get(&channel_map, key);
        if (!chan) {
                chan = channel_new(channel, key, creation ? creation : get_time());
                if (map_set(&channel_map, key, chan, NULL) == -1)
@@ -479,7 +479,10 @@ int admin_hook(const char *hook, struct client_data *cl1, struct client_data *cl
        } else {
                lua_pushnil(L);
        }
-       txt ? lua_pushstring(L, txt) : lua_pushnil(L);
+       if (txt)
+               lua_pushstring(L, txt);
+       else
+               lua_pushnil(L);
        if (LUA_OK != lua_pcall(L, 5, 1, 0)) {
                fprintf(stderr, "%s\n", lua_tostring(L, -1));
                lua_pop(L, 1);
index de6a298..3799814 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -118,7 +118,7 @@ int parsePacket(struct client_data *client) {
        {
                char *p = client->buf;
                { // remove \r
-                       char *end = memchr(p, '\n', client->bufLen);
+                       char *end = (char *)memchr(p, '\n', client->bufLen);
                        if (end > p && end[-1] == '\r')
                                *--end = '\n';
                        if (memchr(p, '\0', end-p)) {
@@ -413,10 +413,11 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                                int res;
                                res = -1;
                                if (!client->saslexternal) {
-                                       username = strchr(client->saslbuf, '\0')+1;
+                                       char *p = strchr(client->saslbuf, '\0')+1;
+                                       username = p;
                                        if (username > client->saslbuf + client->saslbufLen)
                                                goto saslerr;
-                                       char *password = strchr(username, '\0')+1;
+                                       char *password = strchr(p, '\0')+1;
                                        if (password > client->saslbuf + client->saslbufLen)
                                                goto saslerr;
                                        job_password_check(client, username, password, getdatafile("users.txt"), cont_sasl);
@@ -613,7 +614,7 @@ saslcleanup:
                if (!args[0])
                        return err_needmoreparams(client, command), sendbuf(client), 0;
                if (!strcmp(args[0], "0")) {
-                       for (struct channel *chan; (chan = map_pop(&client->channels)); )
+                       for (struct channel *chan; (chan = (struct channel *)map_pop(&client->channels)); )
                                channel_part(client, chan, "I fell for a classic prank", NULL);
                        return 0;
                }
@@ -1138,7 +1139,7 @@ saslcleanup:
                                if (map_set(&client->monitor, nick, /* dummy */ nick, (void **)&existing) == -1)
                                        abort();
                                monitor_count += !existing;
-                               struct client_data *cl = map_get(&client_map, nick);
+                               struct client_data *cl = (struct client_data *)map_get(&client_map, nick);
                                if (cl)
                                        rpl_mononline(client, cl), sendbuf(client);
                                else
@@ -1174,7 +1175,7 @@ saslcleanup:
                case 'S': {
                        const char *key;
                        map_foreach(&client->monitor, &key, 0) {
-                               struct client_data *cl = map_get(&client_map, key);
+                               struct client_data *cl = (struct client_data *)map_get(&client_map, key);
                                if (cl)
                                        rpl_mononline(client, cl), sendbuf(client);
                                else
@@ -1306,9 +1307,9 @@ void sendMOTD(struct client_data *client) {
 }
 
 static void updateNuh(struct client_data *client) {
-       char *n = client->nick ? client->nick : "*";
-       char *u = client->username ? client->username : "*";
-       char *h = client->hostname;
+       const char *n = client->nick ? client->nick : "*";
+       const char *u = client->username ? client->username : "*";
+       const char *h = client->hostname;
        free(client->nuh);
        client->nuh = (char *)malloc(strlen(n) + strlen(u) + strlen(h) + 3);
        if (!client->nuh)
@@ -1516,7 +1517,7 @@ void channel_join(struct client_data *client, const char *channel, const char *c
        char key[33];
        memcpy(key, channel, chanlen+1);
        stringlower(key);
-       struct channel *chan = map_get(&channel_map, key);
+       struct channel *chan = (struct channel *)map_get(&channel_map, key);
        int newchan = !chan;
        if (!chan) {
                chan = channel_new(channel, key, get_time());
@@ -1822,7 +1823,7 @@ struct client_data *findClient(const char *nickname)
                return NULL;
        memcpy(key, nickname, len+1);
        stringlower(key);
-       return map_get(&client_map, key);
+       return (struct client_data *)map_get(&client_map, key);
 }
 struct channel *findChannel(const char *channel)
 {
@@ -1832,5 +1833,5 @@ struct channel *findChannel(const char *channel)
        char key[33];
        memcpy(key, channel, chanlen+1);
        stringlower(key);
-       return map_get(&channel_map, key);
+       return (struct channel *)map_get(&channel_map, key);
 }
index 845a3b7..5e31673 100644 (file)
@@ -418,7 +418,7 @@ int main(int argc, char *argv[])
                                        accept_from_sock((struct listener *)pfd.assoc);
                                break;
                        case SOCKTYPE_CLIENT: {
-                               struct client_data *cl = pfd.assoc;
+                               struct client_data *cl = (struct client_data *)pfd.assoc;
                                int isr = ev & NETPOLL_IN;
                                int isw = ev & NETPOLL_OUT;
                                /* NOTE: recvProc can kill the client, so writing should be done first. */
@@ -429,7 +429,7 @@ int main(int argc, char *argv[])
                                break;
                        }
                        case SOCKTYPE_DYING: {
-                               struct client_data *cl = pfd.assoc;
+                               struct client_data *cl = (struct client_data *)pfd.assoc;
                                int isr = ev & NETPOLL_IN;
                                int isw = ev & NETPOLL_OUT;
                                if (cl->wbufLen)
@@ -471,7 +471,7 @@ int main(int argc, char *argv[])
 #endif
        free(databuf.buf);
        /* free any persistent channels */
-       for (struct channel *chan; (chan = map_pop(&channel_map)); )
+       for (struct channel *chan; (chan = (struct channel *)map_pop(&channel_map)); )
                channel_kill(chan);
        map_free(&client_map);
        map_free(&channel_map);
index 68e659b..d9d5b3d 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -66,7 +66,7 @@ void killConnection(struct client_data *cl, int byChoice)
        }
        update_poll_reg(cl);
        /* Part all channels */
-       for (struct channel *chan; (chan = map_pop(&cl->channels)); )
+       for (struct channel *chan; (chan = (struct channel *)map_pop(&cl->channels)); )
                channel_part(cl, chan, NULL, NULL);
        /* Remove from client_map and get rid of the pending invites */
        if (cl->key) {
@@ -199,7 +199,7 @@ void recvProc(struct client_data *cl) {
                }
                cl->bufLen += bytesRead;
                while(1){
-                       x = memchr(cl->buf, '\n', cl->bufLen);
+                       x = (char *)memchr(cl->buf, '\n', cl->bufLen);
                        if(!x) break;
                        packetReturn = parsePacket(cl);
                        // Client QUIT
index e784aac..4c7abc3 100644 (file)
@@ -161,7 +161,7 @@ void net_poll_fini(void)
 }
 static void net_poll_add_impl(int i)
 {
-       struct epoll_event e = { .data.ptr = fds[i] };
+       struct epoll_event e = { .data = { .ptr = fds[i] }};
        if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fds[i]->fd, &e) == -1) {
                perror("epoll_ctl(EPOLL_CTL_ADD)");
                abort();
@@ -185,7 +185,7 @@ static void net_poll_del_impl(int i)
 }
 static void net_poll_reg_impl(int i, int ev)
 {
-       struct epoll_event e = { .data.ptr = fds[i] };
+       struct epoll_event e = { .data = { .ptr = fds[i] }};
        e.events = (ev & NETPOLL_IN ? EPOLLIN : 0) | (ev & NETPOLL_OUT ? EPOLLOUT : 0);
        if (epoll_ctl(epollfd, EPOLL_CTL_MOD, fds[i]->fd, &e) == -1) {
                perror("epoll_ctl(EPOLL_CTL_MOD)");
@@ -256,7 +256,7 @@ void net_poll_add(SOCKET fd, int type, void *assoc)
        memmove(fds+i+1, fds+i, sizeof(fds[0])*(nfds-i));
        nfds++;
        fds[i] = t;
-       REF(fds[i]) = (struct net_pollfd){ .fd = fd, .type = type, .assoc = assoc };
+       REF(fds[i]) = (struct net_pollfd){ .assoc = assoc, .fd = fd, .type = type };
        net_poll_add_impl(i);
 }
 void net_poll_del(SOCKET fd)
index 0434ad6..9aa24c1 100644 (file)
@@ -21,7 +21,7 @@ void append_strf(struct dynarr *d, const char *s, ...){
        va_list ap;
        va_start(ap, s);
        for (;;) {
-               char *end = strchr(s, '%');
+               const char *end = strchr(s, '%');
                if (!end) {
                        // if format string ends with \n, append \r\n
                        int len = strlen(s);