summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-10-19 11:23:44 -0400
committerAndrew Opalach <andrew@akon.city> 2024-10-19 11:23:44 -0400
commit84f5e594d47abac9a0a450f70ceb2f79322a5c3a (patch)
treedb4348fbf7e8457c4c59f436ec3d903d1411a2d2
parent425c57802f6859976a4940b1d134c2a8d1be8c03 (diff)
downloadlibalabaster-84f5e594d47abac9a0a450f70ceb2f79322a5c3a.tar.gz
libalabaster-84f5e594d47abac9a0a450f70ceb2f79322a5c3a.tar.bz2
libalabaster-84f5e594d47abac9a0a450f70ceb2f79322a5c3a.zip
lib: Only use snprintf variants
Signed-off-by: Andrew Opalach <andrew@akon.city>
-rw-r--r--include/al/lib.h3
-rw-r--r--src/log.c12
2 files changed, 8 insertions, 7 deletions
diff --git a/include/al/lib.h b/include/al/lib.h
index 606d24d..6e0b1a9 100644
--- a/include/al/lib.h
+++ b/include/al/lib.h
@@ -48,7 +48,8 @@ void al_set_alloc(void *(*malloc_func)(size_t), void *(*calloc_func)(size_t, siz
#define al_memset memset
#define al_bzero bzero
#define al_strlen strlen
-#define al_sprintf sprintf
+#define al_snprintf snprintf
+#define al_vsnprintf vsnprintf
#if defined _DEBUG_
#define al_assert assert
#else
diff --git a/src/log.c b/src/log.c
index 3466320..c64ca11 100644
--- a/src/log.c
+++ b/src/log.c
@@ -8,13 +8,13 @@
#define AL_LOG_TEMPLATE "%s:%d %s(): %s -> "
#endif
-#define AL_LOG_MESSAGE_SIZE 511
+#define AL_LOG_MESSAGE_MAX 511
#if !AL_LOG_SKIP
static s32 al_print_default(void *userdata, char *s)
{
(void)userdata;
- s32 ret = al_printf("%*.*s\n", 0, AL_LOG_MESSAGE_SIZE, s);
+ s32 ret = al_printf("%*.*s\n", 0, AL_LOG_MESSAGE_MAX, s);
al_free(s);
return ret;
}
@@ -30,14 +30,14 @@ void al_set_print(s32 (*print_func)(void *, char *), void *userdata)
static char *get_buffer(const char *level, const char *section, const char *fmt, const char *name, const s32 line, const char *func, va_list args)
{
- char *buffer = al_calloc(1, AL_LOG_MESSAGE_SIZE + 1);
+ char *buffer = al_malloc(AL_LOG_MESSAGE_MAX + 1);
#if AL_LOG_USE_SECTION
- s32 prefix = snprintf(buffer, AL_LOG_MESSAGE_SIZE, AL_LOG_TEMPLATE, name, line, func, level, section);
+ s32 prefix = al_snprintf(buffer, AL_LOG_MESSAGE_MAX, AL_LOG_TEMPLATE, name, line, func, level, section);
#else
(void)section;
- s32 prefix = snprintf(buffer, AL_LOG_MESSAGE_SIZE, AL_LOG_TEMPLATE, name, line, func, level);
+ s32 prefix = al_snprintf(buffer, AL_LOG_MESSAGE_MAX, AL_LOG_TEMPLATE, name, line, func, level);
#endif
- prefix += vsnprintf(buffer + prefix, AL_LOG_MESSAGE_SIZE - prefix, fmt, args);
+ prefix += al_vsnprintf(buffer + prefix, AL_LOG_MESSAGE_MAX - prefix, fmt, args);
buffer[strcspn(buffer, "\r\n")] = '\0';
return buffer;
}