]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Fix some compile warnings
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 6 Jun 2025 10:49:46 +0000 (11:49 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 6 Jun 2025 10:50:06 +0000 (11:50 +0100)
contrib/libev/ev.c
contrib/snowball/compiler/generator.c
contrib/snowball/compiler/space.c
test/rspamd_cryptobox_test.c
test/rspamd_dns_test.c

index 230445d2acce88de71b329ae301750c3441f1a6b..0dec50bcdbc87c19792a665a03bde19ab80cb57f 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2025 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 /*
  * libev event processing core, watcher management
  *
@@ -2148,7 +2164,10 @@ typedef struct
   #include "ev_wrap.h"
 
   static struct ev_loop default_loop_struct;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wextern-initializer"
   EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */
+#pragma clang diagnostic pop
 
 #else
 
index eed86c11798ac8630d7f93ea5152df72d50b2a7c..44fbdcea4d92f5715e9f3b93baa7ac17a1428b8b 100644 (file)
@@ -1,4 +1,20 @@
 
+/*
+ * Copyright 2025 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #include <limits.h>  /* for INT_MAX */
 #include <stdio.h>   /* for fprintf etc */
 #include <stdlib.h>  /* for free etc */
@@ -1241,7 +1257,7 @@ static void generate_substring(struct generator * g, struct node * p) {
         g->I[3] = bitmap;
         g->I[4] = shortest_size - 1;
         if (p->mode == m_forward) {
-            sprintf(buf, "z->p[z->c + %d]", shortest_size - 1);
+            snprintf(buf, sizeof(buf), "z->p[z->c + %d]", shortest_size - 1);
             g->S[1] = buf;
             if (shortest_size == 1) {
                 writef(g, "~Mif (z->c >= z->l", p);
index 5b058763a1da9994f68db0e002a595990f270c0f..46c32e0790cab65fe95233d940d8f1b33e992ed3 100644 (file)
@@ -1,11 +1,27 @@
 
-#include <stdio.h>    /* for printf */
-#include <stdlib.h>   /* malloc, free */
-#include <string.h>   /* memmove */
+/*
+ * Copyright 2025 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>  /* for printf */
+#include <stdlib.h> /* malloc, free */
+#include <string.h> /* memmove */
 
 #include "header.h"
 
-#define HEAD 2*sizeof(int)
+#define HEAD 2 * sizeof(int)
 #define EXTENDER 40
 
 
     overwriting.
 */
 
-extern symbol * create_b(int n) {
-    symbol * p = (symbol *) (HEAD + (char *) MALLOC(HEAD + (n + 1) * sizeof(symbol)));
-    CAPACITY(p) = n;
-    SIZE(p) = 0;
-    return p;
+extern symbol *create_b(int n)
+{
+       symbol *p = (symbol *) (HEAD + (char *) MALLOC(HEAD + (n + 1) * sizeof(symbol)));
+       CAPACITY(p) = n;
+       SIZE(p) = 0;
+       return p;
 }
 
-extern void report_b(FILE * out, const symbol * p) {
-    int i;
-    for (i = 0; i < SIZE(p); i++) {
-        if (p[i] > 255) {
-            printf("In report_b, can't convert p[%d] to char because it's 0x%02x\n", i, (int)p[i]);
-            exit(1);
-        }
-        putc(p[i], out);
-    }
+extern void report_b(FILE *out, const symbol *p)
+{
+       int i;
+       for (i = 0; i < SIZE(p); i++) {
+               if (p[i] > 255) {
+                       printf("In report_b, can't convert p[%d] to char because it's 0x%02x\n", i, (int) p[i]);
+                       exit(1);
+               }
+               putc(p[i], out);
+       }
 }
 
-extern void output_str(FILE * outfile, struct str * str) {
-    report_b(outfile, str_data(str));
+extern void output_str(FILE *outfile, struct str *str)
+{
+       report_b(outfile, str_data(str));
 }
 
-extern void lose_b(symbol * p) {
-    if (p == 0) return;
-    FREE((char *) p - HEAD);
+extern void lose_b(symbol *p)
+{
+       if (p == 0) return;
+       FREE((char *) p - HEAD);
 }
 
-extern symbol * increase_capacity(symbol * p, int n) {
-    symbol * q = create_b(CAPACITY(p) + n + EXTENDER);
-    memmove(q, p, CAPACITY(p) * sizeof(symbol));
-    SIZE(q) = SIZE(p);
-    lose_b(p); return q;
+extern symbol *increase_capacity(symbol *p, int n)
+{
+       symbol *q = create_b(CAPACITY(p) + n + EXTENDER);
+       memmove(q, p, CAPACITY(p) * sizeof(symbol));
+       SIZE(q) = SIZE(p);
+       lose_b(p);
+       return q;
 }
 
-extern symbol * move_to_b(symbol * p, int n, const symbol * q) {
-    int x = n - CAPACITY(p);
-    if (x > 0) p = increase_capacity(p, x);
-    memmove(p, q, n * sizeof(symbol)); SIZE(p) = n; return p;
+extern symbol *move_to_b(symbol *p, int n, const symbol *q)
+{
+       int x = n - CAPACITY(p);
+       if (x > 0) p = increase_capacity(p, x);
+       memmove(p, q, n * sizeof(symbol));
+       SIZE(p) = n;
+       return p;
 }
 
-extern symbol * add_to_b(symbol * p, int n, const symbol * q) {
-    int x = SIZE(p) + n - CAPACITY(p);
-    if (x > 0) p = increase_capacity(p, x);
-    memmove(p + SIZE(p), q, n * sizeof(symbol)); SIZE(p) += n; return p;
+extern symbol *add_to_b(symbol *p, int n, const symbol *q)
+{
+       int x = SIZE(p) + n - CAPACITY(p);
+       if (x > 0) p = increase_capacity(p, x);
+       memmove(p + SIZE(p), q, n * sizeof(symbol));
+       SIZE(p) += n;
+       return p;
 }
 
-extern symbol * copy_b(const symbol * p) {
-    int n = SIZE(p);
-    symbol * q = create_b(n);
-    move_to_b(q, n, p);
-    return q;
+extern symbol *copy_b(const symbol *p)
+{
+       int n = SIZE(p);
+       symbol *q = create_b(n);
+       move_to_b(q, n, p);
+       return q;
 }
 
 int space_count = 0;
 
-extern void * check_malloc(int n) {
-    space_count++;
-    return malloc(n);
+extern void *check_malloc(int n)
+{
+       space_count++;
+       return malloc(n);
 }
 
-extern void check_free(void * p) {
-    space_count--;
-    free(p);
+extern void check_free(void *p)
+{
+       space_count--;
+       free(p);
 }
 
 /* To convert a block to a zero terminated string:  */
 
-extern char * b_to_s(const symbol * p) {
-    int n = SIZE(p);
-    char * s = (char *)malloc(n + 1);
-    {
-        int i;
-        for (i = 0; i < n; i++) {
-            if (p[i] > 255) {
-                printf("In b_to_s, can't convert p[%d] to char because it's 0x%02x\n", i, (int)p[i]);
-                exit(1);
-            }
-            s[i] = (char)p[i];
-        }
-    }
-    s[n] = 0;
-    return s;
+extern char *b_to_s(const symbol *p)
+{
+       int n = SIZE(p);
+       char *s = (char *) malloc(n + 1);
+       {
+               int i;
+               for (i = 0; i < n; i++) {
+                       if (p[i] > 255) {
+                               printf("In b_to_s, can't convert p[%d] to char because it's 0x%02x\n", i, (int) p[i]);
+                               exit(1);
+                       }
+                       s[i] = (char) p[i];
+               }
+       }
+       s[n] = 0;
+       return s;
 }
 
 /* To add a zero terminated string to a block. If p = 0 the
    block is created. */
 
-extern symbol * add_s_to_b(symbol * p, const char * s) {
-    int n = strlen(s);
-    int k;
-    if (p == 0) p = create_b(n);
-    k = SIZE(p);
-    {
-        int x = k + n - CAPACITY(p);
-        if (x > 0) p = increase_capacity(p, x);
-    }
-    {
-        int i;
-        for (i = 0; i < n; i++) p[i + k] = s[i];
-    }
-    SIZE(p) += n;
-    return p;
+extern symbol *add_s_to_b(symbol *p, const char *s)
+{
+       int n = strlen(s);
+       int k;
+       if (p == 0) p = create_b(n);
+       k = SIZE(p);
+       {
+               int x = k + n - CAPACITY(p);
+               if (x > 0) p = increase_capacity(p, x);
+       }
+       {
+               int i;
+               for (i = 0; i < n; i++) p[i + k] = s[i];
+       }
+       SIZE(p) += n;
+       return p;
 }
 
 /* The next section defines string handling capabilities in terms
@@ -159,129 +192,151 @@ extern symbol * add_s_to_b(symbol * p, const char * s) {
 /* -------------------------------------------------------------*/
 
 struct str {
-    symbol * data;
+       symbol *data;
 };
 
 /* Create a new string. */
-extern struct str * str_new(void) {
+extern struct str *str_new(void)
+{
 
-    struct str * output = (struct str *) malloc(sizeof(struct str));
-    output->data = create_b(0);
-    return output;
+       struct str *output = (struct str *) malloc(sizeof(struct str));
+       output->data = create_b(0);
+       return output;
 }
 
 /* Delete a string. */
-extern void str_delete(struct str * str) {
+extern void str_delete(struct str *str)
+{
 
-    lose_b(str->data);
-    free(str);
+       lose_b(str->data);
+       free(str);
 }
 
 /* Append a str to this str. */
-extern void str_append(struct str * str, const struct str * add) {
+extern void str_append(struct str *str, const struct str *add)
+{
 
-    symbol * q = add->data;
-    str->data = add_to_b(str->data, SIZE(q), q);
+       symbol *q = add->data;
+       str->data = add_to_b(str->data, SIZE(q), q);
 }
 
 /* Append a character to this str. */
-extern void str_append_ch(struct str * str, char add) {
+extern void str_append_ch(struct str *str, char add)
+{
 
-    symbol q[1];
-    q[0] = add;
-    str->data = add_to_b(str->data, 1, q);
+       symbol q[1];
+       q[0] = add;
+       str->data = add_to_b(str->data, 1, q);
 }
 
 /* Append a low level block to a str. */
-extern void str_append_b(struct str * str, const symbol * q) {
+extern void str_append_b(struct str *str, const symbol *q)
+{
 
-    str->data = add_to_b(str->data, SIZE(q), q);
+       str->data = add_to_b(str->data, SIZE(q), q);
 }
 
 /* Append the tail of a low level block to a str. */
-extern void str_append_b_tail(struct str * str, const symbol * q, int skip) {
-    if (skip < 0 || skip >= SIZE(q)) return;
+extern void str_append_b_tail(struct str *str, const symbol *q, int skip)
+{
+       if (skip < 0 || skip >= SIZE(q)) return;
 
-    str->data = add_to_b(str->data, SIZE(q) - skip, q + skip);
+       str->data = add_to_b(str->data, SIZE(q) - skip, q + skip);
 }
 
 /* Append a (char *, null terminated) string to a str. */
-extern void str_append_string(struct str * str, const char * s) {
+extern void str_append_string(struct str *str, const char *s)
+{
 
-    str->data = add_s_to_b(str->data, s);
+       str->data = add_s_to_b(str->data, s);
 }
 
 /* Append an integer to a str. */
-extern void str_append_int(struct str * str, int i) {
+extern void str_append_int(struct str *str, int i)
+{
 
-    char s[30];
-    sprintf(s, "%d", i);
-    str_append_string(str, s);
+       char s[30];
+       snprintf(s, sizeof(s), "%d", i);
+       str_append_string(str, s);
 }
 
 /* Clear a string */
-extern void str_clear(struct str * str) {
+extern void str_clear(struct str *str)
+{
 
-    SIZE(str->data) = 0;
+       SIZE(str->data) = 0;
 }
 
 /* Set a string */
-extern void str_assign(struct str * str, const char * s) {
+extern void str_assign(struct str *str, const char *s)
+{
 
-    str_clear(str);
-    str_append_string(str, s);
+       str_clear(str);
+       str_append_string(str, s);
 }
 
 /* Copy a string. */
-extern struct str * str_copy(const struct str * old) {
+extern struct str *str_copy(const struct str *old)
+{
 
-    struct str * newstr = str_new();
-    str_append(newstr, old);
-    return newstr;
+       struct str *newstr = str_new();
+       str_append(newstr, old);
+       return newstr;
 }
 
 /* Get the data stored in this str. */
-extern symbol * str_data(const struct str * str) {
+extern symbol *str_data(const struct str *str)
+{
 
-    return str->data;
+       return str->data;
 }
 
 /* Get the length of the str. */
-extern int str_len(const struct str * str) {
+extern int str_len(const struct str *str)
+{
 
-    return SIZE(str->data);
+       return SIZE(str->data);
 }
 
 /* Get the last character of the str.
  *
  * Or -1 if the string is empty.
  */
-extern int str_back(const struct str *str) {
-    return SIZE(str->data) ? str->data[SIZE(str->data) - 1] : -1;
+extern int str_back(const struct str *str)
+{
+       return SIZE(str->data) ? str->data[SIZE(str->data) - 1] : -1;
 }
 
-extern int get_utf8(const symbol * p, int * slot) {
-    int b0, b1;
-    b0 = *p++;
-    if (b0 < 0xC0) {   /* 1100 0000 */
-        * slot = b0; return 1;
-    }
-    b1 = *p++;
-    if (b0 < 0xE0) {   /* 1110 0000 */
-        * slot = (b0 & 0x1F) << 6 | (b1 & 0x3F); return 2;
-    }
-    * slot = (b0 & 0xF) << 12 | (b1 & 0x3F) << 6 | (*p & 0x3F); return 3;
+extern int get_utf8(const symbol *p, int *slot)
+{
+       int b0, b1;
+       b0 = *p++;
+       if (b0 < 0xC0) { /* 1100 0000 */
+               *slot = b0;
+               return 1;
+       }
+       b1 = *p++;
+       if (b0 < 0xE0) { /* 1110 0000 */
+               *slot = (b0 & 0x1F) << 6 | (b1 & 0x3F);
+               return 2;
+       }
+       *slot = (b0 & 0xF) << 12 | (b1 & 0x3F) << 6 | (*p & 0x3F);
+       return 3;
 }
 
-extern int put_utf8(int ch, symbol * p) {
-    if (ch < 0x80) {
-        p[0] = ch; return 1;
-    }
-    if (ch < 0x800) {
-        p[0] = (ch >> 6) | 0xC0;
-        p[1] = (ch & 0x3F) | 0x80; return 2;
-    }
-    p[0] = (ch >> 12) | 0xE0;
-    p[1] = ((ch >> 6) & 0x3F) | 0x80;
-    p[2] = (ch & 0x3F) | 0x80; return 3;
+extern int put_utf8(int ch, symbol *p)
+{
+       if (ch < 0x80) {
+               p[0] = ch;
+               return 1;
+       }
+       if (ch < 0x800) {
+               p[0] = (ch >> 6) | 0xC0;
+               p[1] = (ch & 0x3F) | 0x80;
+               return 2;
+       }
+       p[0] = (ch >> 12) | 0xE0;
+       p[1] = ((ch >> 6) & 0x3F) | 0x80;
+       p[2] = (ch & 0x3F) | 0x80;
+       return 3;
 }
index 03b8334045681ab7b4c60585bf50318c952f84cb..82225d07144fe24fed916ecd65793a7ce947c729 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2024 Vsevolod Stakhov
+ * Copyright 2025 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -153,7 +153,6 @@ create_constrained_split(struct rspamd_cryptobox_segment *seg, int mseg,
 
 void rspamd_cryptobox_test_func(void)
 {
-       void *map;
        unsigned char *begin, *end;
        rspamd_nm_t key;
        rspamd_nonce_t nonce;
@@ -161,9 +160,8 @@ void rspamd_cryptobox_test_func(void)
        struct rspamd_cryptobox_segment *seg;
        double t1, t2;
        int i, cnt, ms;
-       gboolean checked_openssl = FALSE;
 
-       map = create_mapping(mapping_size, &begin, &end);
+       create_mapping(mapping_size, &begin, &end);
 
        ottery_rand_bytes(key, sizeof(key));
        ottery_rand_bytes(nonce, sizeof(nonce));
index d041351df431128d37456c0b3840c9fa6006fc20..ccdc478202e8979c3822a00781424cf59177ce02 100644 (file)
@@ -1,4 +1,20 @@
 
+/*
+ * Copyright 2025 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #include "config.h"
 #include "tests.h"
 #include "dns.h"
@@ -51,6 +67,9 @@ test_dns_cb(struct rdns_reply *reply, gpointer arg)
                        case RDNS_REQUEST_MX:
                                msg_debug("got mx %s:%d", cur->content.mx.name, cur->content.mx.priority);
                                break;
+                       default:
+                               msg_debug("got unknown type %d", cur->type);
+                               break;
                        }
                        cur = cur->next;
                }