]> PatchyGit - patchyircd.git/commitdiff
add explicit casting for (m|c|re)alloc
authorEgor <egor@patchysicp.xyz>
Tue, 21 Jan 2025 03:23:45 +0000 (05:23 +0200)
committerEgor <egor@patchysicp.xyz>
Tue, 21 Jan 2025 03:23:45 +0000 (05:23 +0200)
src/admin.c
src/irc.c
src/job.c
src/main.c
src/map.c
src/net.c
src/util.c

index a0f20f2..fc49f3e 100644 (file)
@@ -293,7 +293,7 @@ static int fn_channel_mode(lua_State *L)
        size_t as, bs;
        const char *a = luaL_checklstring(L, 2, &as);
        const char *b = luaL_optlstring(L, 3, 0, &bs);
-       char *buf = malloc(as+bs+2);
+       char *buf = (char *)malloc(as+bs+2);
        memcpy(buf, a, as+1);
        if (b)
                memcpy(buf+as+1, b, bs+1);
index 9d6d7b0..5ef1ed0 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -340,7 +340,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                        // RFC 4616 spec says the three parts of the response can be up to 255 bytes long
                        // That's 255*3 + 2, but we'll add another NUL byte after the pass, so it's 768.
                        // Base64 encoding adds 4/3 overhead, so the total buffer size is 1024.
-                       client->saslbuf = malloc(1024);
+                       client->saslbuf = (char *)malloc(1024);
                        client->saslbufLen = 0;
                        client->saslexternal = !strcmp(args[0], "EXTERNAL");
                        if (!client->saslbuf)
@@ -505,7 +505,7 @@ saslcleanup:
                                client->webircwait = 2;
                        if (!strcmp(args[1], "biboumi")) {
                                int len = strlen(args[2]);
-                               client->webirchostname = malloc(len+sizeof(".xmpp"));
+                               client->webirchostname = (char *)malloc(len+sizeof(".xmpp"));
                                if (client->webirchostname) {
                                        memcpy(client->webirchostname, args[2], len);
                                        memcpy(client->webirchostname+len, ".xmpp", sizeof(".xmpp"));
@@ -1309,7 +1309,7 @@ static void updateNuh(struct client_data *client) {
        char *u = client->username ? client->username : "*";
        char *h = client->hostname;
        free(client->nuh);
-       client->nuh = malloc(strlen(n) + strlen(u) + strlen(h) + 3);
+       client->nuh = (char *)malloc(strlen(n) + strlen(u) + strlen(h) + 3);
        if (!client->nuh)
                abort();
        sprintf(client->nuh, "%s!%s@%s", n, u, h);
@@ -1575,7 +1575,7 @@ void channel_join(struct client_data *client, const char *channel, const char *c
 }
 struct channel *channel_new(const char *channel, const char *key, time_t creation)
 {
-       struct channel *chan = malloc(sizeof(struct channel));
+       struct channel *chan = (struct channel *)malloc(sizeof(struct channel));
        if (!chan) abort();
        memset(chan, 0, sizeof(struct channel));
        chan->creation = creation;
index 4f1541b..8a82e73 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -112,7 +112,7 @@ void job_add(struct client_data *cl, jobproc_t job, contproc_t then, char *data,
        struct jobent ent = { cl, job, then, data, len };
        if (joblen == jobcap) {
                jobcap = jobcap == 0 ? 16 : jobcap * 2;
-               jobtab = realloc(jobtab, sizeof(struct jobent)*jobcap);
+               jobtab = (struct jobent *)realloc(jobtab, sizeof(struct jobent)*jobcap);
                if (!jobtab)
                        abort();
        }
@@ -159,7 +159,7 @@ void job_password_check(struct client_data *client, const char *key, const char
        } else {
                size_t pwlen = strlen(pw)+1;
                size_t len = pwlen+strlen(salt)+1;
-               char *buf = malloc(len);
+               char *buf = (char *)malloc(len);
                if (!buf)
                        abort();
                memcpy(buf, pw, pwlen);
index 0d4bb29..0536567 100644 (file)
@@ -245,7 +245,7 @@ int main(int argc, char *argv[])
        admin_init();
 #endif
        set_handler();
-       databuf.buf = malloc(sizeof(char) * 512);
+       databuf.buf = (char *)malloc(sizeof(char) * 512);
        databuf.cap = 512;
 
        struct tls *tls_ctx = NULL;
@@ -343,7 +343,7 @@ int main(int argc, char *argv[])
                                if (sp && bang && bang < sp) {
                                        int nlen = bang - fake->buf - 1;
                                        if (memcmp(&fake->buf[1], fake->nick, nlen) != 0) {
-                                               char *nnick = malloc(nlen+1);
+                                               char *nnick = (char *)malloc(nlen+1);
                                                if (!nnick)
                                                        abort();
                                                memcpy(nnick, &fake->buf[1], nlen);
index 3f95dbe..bfd1ebc 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -46,14 +46,14 @@ int map_set(map_t *root, const char *key, const void *value, void **oldvalue)
                if (value) {
                        if (root->len == root->cap) {
                                int ncap = root->cap ? root->cap*2 : 2;
-                               struct map_value *nptr = realloc(root->ptr, sizeof(struct map_value)*ncap);
+                               struct map_value *nptr = (struct map_value *)realloc(root->ptr, sizeof(struct map_value)*ncap);
                                if (!nptr)
                                        return -1;
                                root->ptr = nptr;
                                root->cap = ncap;
                        }
                        int slen = strlen(key)+1;
-                       char *nkey = malloc(slen);
+                       char *nkey = (char *)malloc(slen);
                        if (!nkey)
                                return -1;
                        memcpy(nkey, key, slen);
index 38daed2..44b47b6 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -5,7 +5,7 @@
 
 struct client_data *allocClient(void)
 {
-       return calloc(1, sizeof(struct client_data));
+       return (struct client_data *)calloc(1, sizeof(struct client_data));
 }
 
 void update_poll_reg(struct client_data *cl)
index 25df345..0434ad6 100644 (file)
@@ -7,7 +7,7 @@ static void append_strn(struct dynarr *d, const char *s, int len){
        if (d->len + len > d->cap){
                while (d->len + len > d->cap)
                        d->cap *= 2;
-               void *ndata = realloc(d->buf, d->cap);
+               char *ndata = (char *)realloc(d->buf, d->cap);
                if(!ndata) abort();
                d->buf = ndata;
        }
@@ -78,7 +78,7 @@ void stringlower(char *s) {
 }
 char *mystrdup(const char *s) {
        int len = strlen(s);
-       char *buf = malloc(len+1);
+       char *buf = (char *)malloc(len+1);
        if (buf)
                memcpy(buf, s, len+1);
        return buf;