Repository: profanity-im/profanity (c)

Issue:
Slashguard spams console until I type something
```
Profanity, version 0.15.0dev.master.edda887a
Copyright (C) 2012 - 2019 James Booth <boothj5web@gmail.com>.
Copyright (C) 2019 - 2025 Michael Vetter <jubalh@iodoru.org>.
License GPLv3+: GNU GPL version 3 or later <https://www.gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Build information:
XMPP library: libstrophe
Desktop notification support: Enabled
OTR support: Enabled (libotr 4.1.1)
PGP support: Enabled (libgpgme 1.18.0)
OMEMO support: Enabled
C plugins: Enabled
Python plugins: Enabled (3.11.2)
GTK icons/clipboard: Enabled
GDK Pixbuf: Enabled
```

I realized slashguard is spamming in the console until I type something:

https://github.com/user-attachments/assets/206775b7-036f-43eb-8199-16539c5bb5ee


Discussion:

Patch:
diff --git a/Makefile.am b/Makefile.am
--- a/Makefile.am
+++ b/Makefile.am
@@ -124,6 +124,7 @@ unittest_sources = \
 	src/event/server_events.c src/event/server_events.h \
 	src/event/client_events.c src/event/client_events.h \
 	src/ui/tray.h src/ui/tray.c \
+	tests/prof_cmocka.h \
 	tests/unittests/xmpp/stub_vcard.c \
 	tests/unittests/xmpp/stub_avatar.c \
 	tests/unittests/xmpp/stub_ox.c \
@@ -169,6 +170,7 @@ unittest_sources = \
 	tests/unittests/unittests.c
 
 functionaltest_sources = \
+	tests/prof_cmocka.h \
 	tests/functionaltests/proftest.c tests/functionaltests/proftest.h \
 	tests/functionaltests/test_connect.c tests/functionaltests/test_connect.h \
 	tests/functionaltests/test_ping.c tests/functionaltests/test_ping.h \
@@ -283,6 +285,7 @@ endif
 
 TESTS = tests/unittests/unittests
 check_PROGRAMS = tests/unittests/unittests
+tests_unittests_unittests_CPPFLAGS = -Itests/
 tests_unittests_unittests_SOURCES = $(unittest_sources)
 tests_unittests_unittests_LDADD = -lcmocka
 
@@ -346,9 +349,13 @@ endif
 .PHONY: my-prof.supp
 my-prof.supp:
 	@sed '/^# AUTO-GENERATED START/q' prof.supp > $@
+	@printf "\n\n# glib\n" >> $@
 	@cat /usr/share/glib-2.0/valgrind/glib.supp >> $@
+	@printf "\n\n# Python\n" >> $@
 	@wget -O- https://raw.githubusercontent.com/python/cpython/refs/tags/v`python3 --version | cut -d' ' -f2`/Misc/valgrind-python.supp >> $@
+	@printf "\n\n# gtk\n" >> $@
 	@test -z "@GTK_VERSION@" || wget -O- https://raw.githubusercontent.com/GNOME/gtk/refs/tags/@GTK_VERSION@/gtk.supp >> $@
+	@printf "\n\n# more gtk\n" >> $@
 	@test -z "@GTK_VERSION@" || cat /usr/share/gtk-3.0/valgrind/gtk.supp >> $@
 
 check-unit: tests/unittests/unittests
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -1662,7 +1662,7 @@ char*
 cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean previous)
 {
     unsigned int output_off = 0;
-    char* tmp;
+    char* tmp = NULL;
 
     // strip command
     char* inpcp = (char*)input + strlen(startstr);
@@ -1674,38 +1674,36 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean
 
     // strip quotes
     if (*inpcp == '"') {
-        tmp = strchr(inpcp + 1, '"');
+        tmp = strrchr(inpcp + 1, '"');
         if (tmp) {
             *tmp = '\0';
         }
         tmp = strdup(inpcp + 1);
         free(inpcp);
         inpcp = tmp;
+        tmp = NULL;
     }
 
     // expand ~ to $HOME
     if (inpcp[0] == '~' && inpcp[1] == '/') {
-        tmp = g_strdup_printf("%s/%sfoo", getenv("HOME"), inpcp + 2);
-        if (!tmp) {
+        char* home = getenv("HOME");
+        if (!home) {
             free(inpcp);
             return NULL;
         }
-        output_off = strlen(getenv("HOME")) + 1;
+        tmp = g_strdup_printf("%s/%sfoo", home, inpcp + 2);
+        output_off = strlen(home) + 1;
     } else {
         tmp = g_strdup_printf("%sfoo", inpcp);
-        if (!tmp) {
-            free(inpcp);
-            return NULL;
-        }
     }
     free(inpcp);
-    inpcp = tmp;
+    if (!tmp) {
+        return NULL;
+    }
 
-    char* inpcp2 = strdup(inpcp);
-    char* foofile = strdup(basename(inpcp2));
-    char* directory = strdup(dirname(inpcp));
-    free(inpcp);
-    free(inpcp2);
+    char* foofile = strdup(basename(tmp));
+    char* directory = strdup(dirname(tmp));
+    g_free(tmp);
 
     GArray* files = g_array_new(TRUE, FALSE, sizeof(char*));
     g_array_set_clear_func(files, (GDestroyNotify)_filepath_item_free);
@@ -1724,40 +1722,26 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean
                 continue;
             }
 
-            char* acstring;
+            char* acstring = NULL;
             if (output_off) {
                 tmp = g_strdup_printf("%s/%s", directory, dir->d_name);
-                if (!tmp) {
-                    free(directory);
-                    free(foofile);
-                    return NULL;
-                }
-                acstring = g_strdup_printf("~/%s", tmp + output_off);
-                if (!acstring) {
-                    free(directory);
-                    free(foofile);
-                    return NULL;
+                if (tmp) {
+                    acstring = g_strdup_printf("~/%s", tmp + output_off);
+                    g_free(tmp);
                 }
-                free(tmp);
             } else if (strcmp(directory, "/") == 0) {
                 acstring = g_strdup_printf("/%s", dir->d_name);
-                if (!acstring) {
-                    free(directory);
-                    free(foofile);
-                    return NULL;
-                }
             } else {
                 acstring = g_strdup_printf("%s/%s", directory, dir->d_name);
-                if (!acstring) {
-                    free(directory);
-                    free(foofile);
-                    return NULL;
-                }
+            }
+            if (!acstring) {
+                g_array_free(files, TRUE);
+                free(foofile);
+                free(directory);
+                return NULL;
             }
 
-            char* acstring_cpy = strdup(acstring);
-            g_array_append_val(files, acstring_cpy);
-            free(acstring);
+            g_array_append_val(files, acstring);
         }
         closedir(d);
     }
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -8565,19 +8565,20 @@ cmd_omemo_trust_mode(ProfWin* window, const char* const command, gchar** args)
 {
 #ifdef HAVE_OMEMO
 
+    auto_gchar gchar* trust_mode = prefs_get_string(PREF_OMEMO_TRUST_MODE);
     if (!args[1]) {
-        cons_show("Current trust mode is %s", prefs_get_string(PREF_OMEMO_TRUST_MODE));
+        cons_show("Current trust mode is %s", trust_mode);
         return TRUE;
     }
 
     if (g_strcmp0(args[1], "manual") == 0) {
-        cons_show("Current trust mode is %s - setting to %s", prefs_get_string(PREF_OMEMO_TRUST_MODE), args[1]);
+        cons_show("Current trust mode is %s - setting to %s", trust_mode, args[1]);
         cons_show("You need to trust all OMEMO fingerprints manually");
     } else if (g_strcmp0(args[1], "firstusage") == 0) {
-        cons_show("Current trust mode is %s - setting to %s", prefs_get_string(PREF_OMEMO_TRUST_MODE), args[1]);
+        cons_show("Current trust mode is %s - setting to %s", trust_mode, args[1]);
         cons_show("The first seen OMEMO fingerprints will be trusted automatically - new keys must be trusted manually");
     } else if (g_strcmp0(args[1], "blind") == 0) {
-        cons_show("Current trust mode is %s - setting to %s", prefs_get_string(PREF_OMEMO_TRUST_MODE), args[1]);
+        cons_show("Current trust mode is %s - setting to %s", trust_mode, args[1]);
         cons_show("ALL OMEMO fingerprints will be trusted automatically");
     } else {
         cons_bad_cmd_usage(command);
diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c
--- a/src/plugins/python_plugins.c
+++ b/src/plugins/python_plugins.c
@@ -86,10 +86,16 @@ python_get_version_number(void)
     return version_number;
 }
 
+static void
+_unref_module(PyObject* module)
+{
+    Py_XDECREF(module);
+}
+
 void
 python_env_init(void)
 {
-    loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)Py_XDECREF);
+    loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_unref_module);
 
     python_init_prof();
 
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -170,6 +170,29 @@ create_input_window(void)
     _inp_win_update_virtual();
 }
 
+static gboolean
+_inp_slashguard_check(void)
+{
+    if (get_password)
+        return false;
+    /* ignore empty and quoted messages */
+    if (inp_line == NULL || inp_line[0] == '\0' || inp_line[0] == '>')
+        return false;
+    if (!prefs_get_boolean(PREF_SLASH_GUARD))
+        return false;
+    size_t n = 1;
+    while (inp_line[n] != '\0' && n < 4) {
+        if (inp_line[n] == '/') {
+            cons_show("Your text contains a slash in the first 4 characters");
+            free(inp_line);
+            inp_line = NULL;
+            return true;
+        }
+        n++;
+    }
+    return false;
+}
+
 char*
 inp_readline(void)
 {
@@ -203,17 +226,7 @@ inp_readline(void)
         chat_state_idle();
     }
 
-    if (inp_line) {
-        if (!get_password && prefs_get_boolean(PREF_SLASH_GUARD)) {
-            // ignore quoted messages
-            if (strlen(inp_line) > 1 && inp_line[0] != '>') {
-                char* res = (char*)memchr(inp_line + 1, '/', 3);
-                if (res) {
-                    cons_show("Your text contains a slash in the first 4 characters");
-                    return NULL;
-                }
-            }
-        }
+    if (inp_line && !_inp_slashguard_check()) {
         char* ret = inp_line;
         inp_line = NULL;
         return ret;


Test patch:
diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c
--- a/tests/functionaltests/functionaltests.c
+++ b/tests/functionaltests/functionaltests.c
@@ -1,10 +1,7 @@
-#include <stdarg.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <sys/stat.h>
 
 #include "config.h"
diff --git a/tests/functionaltests/proftest.c b/tests/functionaltests/proftest.c
--- a/tests/functionaltests/proftest.c
+++ b/tests/functionaltests/proftest.c
@@ -2,11 +2,8 @@
 #include <sys/wait.h>
 #include <glib.h>
 
-#include <setjmp.h>
-#include <stdarg.h>
-#include <stddef.h>
 #include <stdlib.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdio.h>
 #include <unistd.h>
 #include <errno.h>
diff --git a/tests/functionaltests/test_carbons.c b/tests/functionaltests/test_carbons.c
--- a/tests/functionaltests/test_carbons.c
+++ b/tests/functionaltests/test_carbons.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_chat_session.c b/tests/functionaltests/test_chat_session.c
--- a/tests/functionaltests/test_chat_session.c
+++ b/tests/functionaltests/test_chat_session.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_connect.c b/tests/functionaltests/test_connect.c
--- a/tests/functionaltests/test_connect.c
+++ b/tests/functionaltests/test_connect.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_disconnect.c b/tests/functionaltests/test_disconnect.c
--- a/tests/functionaltests/test_disconnect.c
+++ b/tests/functionaltests/test_disconnect.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_message.c b/tests/functionaltests/test_message.c
--- a/tests/functionaltests/test_message.c
+++ b/tests/functionaltests/test_message.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_muc.c b/tests/functionaltests/test_muc.c
--- a/tests/functionaltests/test_muc.c
+++ b/tests/functionaltests/test_muc.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_ping.c b/tests/functionaltests/test_ping.c
--- a/tests/functionaltests/test_ping.c
+++ b/tests/functionaltests/test_ping.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_presence.c b/tests/functionaltests/test_presence.c
--- a/tests/functionaltests/test_presence.c
+++ b/tests/functionaltests/test_presence.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_receipts.c b/tests/functionaltests/test_receipts.c
--- a/tests/functionaltests/test_receipts.c
+++ b/tests/functionaltests/test_receipts.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_rooms.c b/tests/functionaltests/test_rooms.c
--- a/tests/functionaltests/test_rooms.c
+++ b/tests/functionaltests/test_rooms.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_roster.c b/tests/functionaltests/test_roster.c
--- a/tests/functionaltests/test_roster.c
+++ b/tests/functionaltests/test_roster.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/functionaltests/test_software.c b/tests/functionaltests/test_software.c
--- a/tests/functionaltests/test_software.c
+++ b/tests/functionaltests/test_software.c
@@ -1,8 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/prof_cmocka.h b/tests/prof_cmocka.h
new file mode 100644
--- /dev/null
+++ b/tests/prof_cmocka.h
@@ -0,0 +1,5 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
diff --git a/tests/unittests/chatlog/stub_chatlog.c b/tests/unittests/chatlog/stub_chatlog.c
--- a/tests/unittests/chatlog/stub_chatlog.c
+++ b/tests/unittests/chatlog/stub_chatlog.c
@@ -21,8 +21,7 @@
  */
 
 #include <glib.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 
 #include <xmpp/xmpp.h>
 
diff --git a/tests/unittests/config/stub_accounts.c b/tests/unittests/config/stub_accounts.c
--- a/tests/unittests/config/stub_accounts.c
+++ b/tests/unittests/config/stub_accounts.c
@@ -1,8 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 
 #include "common.h"
 #include "config/account.h"
diff --git a/tests/unittests/database/stub_database.c b/tests/unittests/database/stub_database.c
--- a/tests/unittests/database/stub_database.c
+++ b/tests/unittests/database/stub_database.c
@@ -21,8 +21,7 @@
  */
 
 #include <glib.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 
 #include "database.h"
 
diff --git a/tests/unittests/helpers.c b/tests/unittests/helpers.c
--- a/tests/unittests/helpers.c
+++ b/tests/unittests/helpers.c
@@ -1,8 +1,5 @@
-#include <setjmp.h>
-#include <stdarg.h>
-#include <stddef.h>
 #include <stdlib.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <glib.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/tests/unittests/log/stub_log.c b/tests/unittests/log/stub_log.c
--- a/tests/unittests/log/stub_log.c
+++ b/tests/unittests/log/stub_log.c
@@ -20,10 +20,8 @@
  *
  */
 
-#include <stdint.h>
 #include <glib.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 
 #include "log.h"
 
diff --git a/tests/unittests/otr/stub_otr.c b/tests/unittests/otr/stub_otr.c
--- a/tests/unittests/otr/stub_otr.c
+++ b/tests/unittests/otr/stub_otr.c
@@ -2,10 +2,7 @@
 #include <libotr/message.h>
 #include <glib.h>
 
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 
 #include "config/account.h"
 
diff --git a/tests/unittests/test_autocomplete.c b/tests/unittests/test_autocomplete.c
--- a/tests/unittests/test_autocomplete.c
+++ b/tests/unittests/test_autocomplete.c
@@ -1,9 +1,5 @@
 #include <glib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 
 #include "xmpp/contact.h"
diff --git a/tests/unittests/test_callbacks.c b/tests/unittests/test_callbacks.c
--- a/tests/unittests/test_callbacks.c
+++ b/tests/unittests/test_callbacks.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_chat_session.c b/tests/unittests/test_chat_session.c
--- a/tests/unittests/test_chat_session.c
+++ b/tests/unittests/test_chat_session.c
@@ -1,10 +1,6 @@
-#include <stdarg.h>
 #include <string.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
-#include <stdint.h>
 
 #include "xmpp/chat_session.h"
 
diff --git a/tests/unittests/test_cmd_account.c b/tests/unittests/test_cmd_account.c
--- a/tests/unittests/test_cmd_account.c
+++ b/tests/unittests/test_cmd_account.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_alias.c b/tests/unittests/test_cmd_alias.c
--- a/tests/unittests/test_cmd_alias.c
+++ b/tests/unittests/test_cmd_alias.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_bookmark.c b/tests/unittests/test_cmd_bookmark.c
--- a/tests/unittests/test_cmd_bookmark.c
+++ b/tests/unittests/test_cmd_bookmark.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_connect.c b/tests/unittests/test_cmd_connect.c
--- a/tests/unittests/test_cmd_connect.c
+++ b/tests/unittests/test_cmd_connect.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_disconnect.c b/tests/unittests/test_cmd_disconnect.c
--- a/tests/unittests/test_cmd_disconnect.c
+++ b/tests/unittests/test_cmd_disconnect.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/unittests/test_cmd_join.c b/tests/unittests/test_cmd_join.c
--- a/tests/unittests/test_cmd_join.c
+++ b/tests/unittests/test_cmd_join.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_otr.c b/tests/unittests/test_cmd_otr.c
--- a/tests/unittests/test_cmd_otr.c
+++ b/tests/unittests/test_cmd_otr.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_pgp.c b/tests/unittests/test_cmd_pgp.c
--- a/tests/unittests/test_cmd_pgp.c
+++ b/tests/unittests/test_cmd_pgp.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_presence.c b/tests/unittests/test_cmd_presence.c
--- a/tests/unittests/test_cmd_presence.c
+++ b/tests/unittests/test_cmd_presence.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_rooms.c b/tests/unittests/test_cmd_rooms.c
--- a/tests/unittests/test_cmd_rooms.c
+++ b/tests/unittests/test_cmd_rooms.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_roster.c b/tests/unittests/test_cmd_roster.c
--- a/tests/unittests/test_cmd_roster.c
+++ b/tests/unittests/test_cmd_roster.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_cmd_sub.c b/tests/unittests/test_cmd_sub.c
--- a/tests/unittests/test_cmd_sub.c
+++ b/tests/unittests/test_cmd_sub.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c
--- a/tests/unittests/test_common.c
+++ b/tests/unittests/test_common.c
@@ -1,11 +1,7 @@
 #include "xmpp/resource.h"
 #include "common.h"
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
-#include <stdint.h>
 
 void
 replace_one_substr(void** state)
diff --git a/tests/unittests/test_contact.c b/tests/unittests/test_contact.c
--- a/tests/unittests/test_contact.c
+++ b/tests/unittests/test_contact.c
@@ -1,9 +1,6 @@
 #include <glib.h>
-#include <stdarg.h>
 #include <string.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 
 #include "xmpp/contact.h"
diff --git a/tests/unittests/test_form.c b/tests/unittests/test_form.c
--- a/tests/unittests/test_form.c
+++ b/tests/unittests/test_form.c
@@ -1,8 +1,5 @@
-#include <stdarg.h>
 #include <string.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 
 #include "xmpp/form.h"
diff --git a/tests/unittests/test_jid.c b/tests/unittests/test_jid.c
--- a/tests/unittests/test_jid.c
+++ b/tests/unittests/test_jid.c
@@ -1,8 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 
 #include "xmpp/jid.h"
diff --git a/tests/unittests/test_keyhandlers.c b/tests/unittests/test_keyhandlers.c
--- a/tests/unittests/test_keyhandlers.c
+++ b/tests/unittests/test_keyhandlers.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/unittests/test_muc.c b/tests/unittests/test_muc.c
--- a/tests/unittests/test_muc.c
+++ b/tests/unittests/test_muc.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 
 #include "xmpp/muc.h"
diff --git a/tests/unittests/test_parser.c b/tests/unittests/test_parser.c
--- a/tests/unittests/test_parser.c
+++ b/tests/unittests/test_parser.c
@@ -1,8 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 
 #include "tools/parser.h"
diff --git a/tests/unittests/test_plugins_disco.c b/tests/unittests/test_plugins_disco.c
--- a/tests/unittests/test_plugins_disco.c
+++ b/tests/unittests/test_plugins_disco.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 
 #include "plugins/disco.h"
diff --git a/tests/unittests/test_preferences.c b/tests/unittests/test_preferences.c
--- a/tests/unittests/test_preferences.c
+++ b/tests/unittests/test_preferences.c
@@ -1,8 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/test_roster_list.c b/tests/unittests/test_roster_list.c
--- a/tests/unittests/test_roster_list.c
+++ b/tests/unittests/test_roster_list.c
@@ -1,11 +1,7 @@
 #include <glib.h>
-#include <stdarg.h>
 #include <string.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
-#include <stdint.h>
 
 #include "xmpp/contact.h"
 #include "xmpp/roster_list.h"
diff --git a/tests/unittests/test_server_events.c b/tests/unittests/test_server_events.c
--- a/tests/unittests/test_server_events.c
+++ b/tests/unittests/test_server_events.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c
--- a/tests/unittests/ui/stub_ui.c
+++ b/tests/unittests/ui/stub_ui.c
@@ -3,8 +3,7 @@
 #include <glib.h>
 #include <wchar.h>
 
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 
 #include "ui/window.h"
 #include "ui/ui.h"
diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c
--- a/tests/unittests/unittests.c
+++ b/tests/unittests/unittests.c
@@ -1,10 +1,7 @@
-#include <stdarg.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 #include <sys/stat.h>
 #include <stdlib.h>
 #include <locale.h>
diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c
--- a/tests/unittests/xmpp/stub_xmpp.c
+++ b/tests/unittests/xmpp/stub_xmpp.c
@@ -1,7 +1,4 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
+#include "prof_cmocka.h"
 
 #include "xmpp/xmpp.h"