aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--FICS/build.mk1
-rw-r--r--FICS/maxxes-utils.c46
-rw-r--r--FICS/maxxes-utils.h22
3 files changed, 69 insertions, 0 deletions
diff --git a/FICS/build.mk b/FICS/build.mk
index 321cb87..e807dec 100644
--- a/FICS/build.mk
+++ b/FICS/build.mk
@@ -18,6 +18,7 @@ OBJS = $(SRC_DIR)adminproc.o\
$(SRC_DIR)legal.o\
$(SRC_DIR)lists.o\
$(SRC_DIR)matchproc.o\
+ $(SRC_DIR)maxxes-utils.o\
$(SRC_DIR)movecheck.o\
$(SRC_DIR)multicol.o\
$(SRC_DIR)network.o\
diff --git a/FICS/maxxes-utils.c b/FICS/maxxes-utils.c
new file mode 100644
index 0000000..7db8369
--- /dev/null
+++ b/FICS/maxxes-utils.c
@@ -0,0 +1,46 @@
+// SPDX-FileCopyrightText: 2024 Markus Uhlin <maxxe@rpblc.net>
+// SPDX-License-Identifier: ISC
+
+#include <err.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#if __linux__
+#include <bsd/string.h>
+#endif
+
+#include "maxxes-utils.h"
+
+void
+snprintf_trunc_chk(const char *file, const long int line,
+ char *str, size_t size, const char *format, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, format);
+ ret = vsnprintf(str, size, format, ap);
+ va_end(ap);
+
+ if (ret < 0 || (size_t)ret >= size)
+ warnx("%s:%ld: warning: vsnprintf() truncated", file, line);
+}
+
+void
+strlcpy_trunc_chk(char *dst, const char *src, size_t dstsize,
+ const char *file,
+ const long int line)
+{
+ if (strlcpy(dst, src, dstsize) >= dstsize)
+ warnx("%s:%ld: warning: strlcpy() truncated", file, line);
+}
+
+void
+strlcat_trunc_chk(char *dst, const char *src, size_t dstsize,
+ const char *file,
+ const long int line)
+{
+ if (strlcat(dst, src, dstsize) >= dstsize)
+ warnx("%s:%ld: warning: strlcat() truncated", file, line);
+}
diff --git a/FICS/maxxes-utils.h b/FICS/maxxes-utils.h
new file mode 100644
index 0000000..667151f
--- /dev/null
+++ b/FICS/maxxes-utils.h
@@ -0,0 +1,22 @@
+#ifndef MAXXES_UTILITIES_H
+#define MAXXES_UTILITIES_H
+
+#include <stddef.h>
+
+#include "common.h"
+
+#define msnprintf(p_str, p_size, ...) \
+ snprintf_trunc_chk(__FILE__, __LINE__, (p_str), (p_size), __VA_ARGS__)
+#define mstrlcpy(p_dst, p_src, p_dstsize) \
+ strlcpy_trunc_chk((p_dst), (p_src), (p_dstsize), __FILE__, __LINE__)
+#define mstrlcat(p_dst, p_src, p_dstsize) \
+ strlcat_trunc_chk((p_dst), (p_src), (p_dstsize), __FILE__, __LINE__)
+
+void snprintf_trunc_chk(const char *file, const long int line,
+ char *str, size_t size, const char *format, ...) PRINTFLIKE(5);
+void strlcpy_trunc_chk(char *dst, const char *src, size_t dstsize,
+ const char *, const long int);
+void strlcat_trunc_chk(char *dst, const char *src, size_t dstsize,
+ const char *, const long int);
+
+#endif