Update dstr to remove MSVC warnings

This commit is contained in:
Abdelrahman Said 2024-06-09 18:25:37 +01:00
parent a85508e0a4
commit 6c82898225

View File

@ -1,6 +1,7 @@
#include "dstr.h" #include "dstr.h"
#include "aliases.h" #include "aliases.h"
#include "mem_arena.h" #include "mem_arena.h"
#include "platform.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -13,7 +14,12 @@
struct dstr { struct dstr {
u64 capacity; u64 capacity;
u64 size; u64 size;
#ifdef WAPP_PLATFORM_WINDOWS
char *buf;
#else
char buf[]; char buf[];
#endif // WAPP_PLATFORM_WINDOWS
}; };
String *wapp_dstr_with_capacity(u64 capacity, Arena *arena) { String *wapp_dstr_with_capacity(u64 capacity, Arena *arena) {
@ -97,8 +103,19 @@ StringUpdate wapp_dstr_concat(String **dst, const char *src, Arena *arena) {
u64 new_length = (*dst)->size + src_length; u64 new_length = (*dst)->size + src_length;
#ifdef WAPP_PLATFORM_WINDOWS
char *str =
wapp_mem_util_alloc(NULL, new_length + 1, WAPP_MEM_ACCESS_READ_WRITE,
WAPP_MEM_ALLOC_RESERVE | WAPP_MEM_ALLOC_COMMIT,
WAPP_MEM_INIT_INITIALISED);
if (!str) {
return (StringUpdate){.updated = false, .str = *dst};
}
#else
char str[new_length + 1]; char str[new_length + 1];
memset(str, 0, new_length + 1); memset(str, 0, new_length + 1);
#endif
strncpy(str, (*dst)->buf, (*dst)->size); strncpy(str, (*dst)->buf, (*dst)->size);
strncat(str, src, new_length + 1 - (*dst)->size); strncat(str, src, new_length + 1 - (*dst)->size);