aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoe <rbo@gmx.us>2025-10-21 18:40:10 +0200
committerjoe <rbo@gmx.us>2025-10-21 18:40:10 +0200
commitb5792da54d4196e6fedc74abdf1f859b40b44b08 (patch)
tree95733b58b5c55154375ffe03ae06aa0289c3aeb4
parentup (diff)
downloadkirc-b5792da54d4196e6fedc74abdf1f859b40b44b08.tar.gz
kirc-b5792da54d4196e6fedc74abdf1f859b40b44b08.tar.bz2
kirc-b5792da54d4196e6fedc74abdf1f859b40b44b08.tar.xz
kirc-b5792da54d4196e6fedc74abdf1f859b40b44b08.tar.zst
kirc-b5792da54d4196e6fedc74abdf1f859b40b44b08.zip
fixed build err, colors for self
-rw-r--r--Makefile2
-rw-r--r--kirc.c32
2 files changed, 21 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 1ceb706..1ecb5b8 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ ALL_WARNING = -Wall -Werror -Wextra -Wno-unused-result -pedantic -std=c99
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man
-CFLAGS = -march=native -O2 -pipe
+CFLAGS = -march=native -O3 -pipe
# CFLAGS = -march=native -O0 -pipe -g3
# CFLAGS += -fsanitize=address
diff --git a/kirc.c b/kirc.c
index 76ab307..28963cf 100644
--- a/kirc.c
+++ b/kirc.c
@@ -598,21 +598,29 @@ static char *ctime_now(char *buf)
return buf;
}
-static inline void fast_itoa(int value, char *str) {
- char *ptr;
+static inline void fast_itoa(int value, char *str, size_t size) {
char tmp;
+ int len;
- ptr = str;
- while (value > 0) {
- *ptr = (value % 10) + 48;
+ if (size == 0) {
+ return;
+ }
+ if (value == 0) {
+ str[0] = '0';
+ str[1] = '\0';
+ return;
+ }
+ len = 0;
+ while (value > 0 && len < (int)size - 1) {
+ str[len] = (value % 10) + 48;
value /= 10;
- ptr++;
+ len++;
}
- *ptr = '\0';
- for (char *a = str, *b = ptr - 1; a < b; a++, b--) {
- tmp = *a;
- *a = *b;
- *b = tmp;
+ str[len] = '\0';
+ for (int i = 0; i < len / 2; i++) {
+ tmp = str[i];
+ str[i] = str[len - 1 - i];
+ str[len - 1 - i] = tmp;
}
}
@@ -640,7 +648,7 @@ static inline void set_color(char* cbuf, const char *str) {
c += 90 - 7;
}
strcpy(cbuf, "\x1b[");
- fast_itoa(c, buf);
+ fast_itoa(c, buf, sizeof(buf));
strcat(cbuf, buf);
strcat(cbuf, "m");
}