Get md_stb_sprintf running under ubsan, with zig compiler

main
parent a4374d7f8b
commit 50a9252df3

3
.gitignore vendored

@ -1,6 +1,9 @@
# Visual studio stuff
.vs/
# ctags
tags
# Clion stuff
.idea/
cmake-build-debug/

@ -6,9 +6,17 @@
#pragma warning(disable : 4996) // nonsense about fopen being insecure
#if defined(__clang__)
#define no_ubsan __attribute__((no_sanitize("undefined")))
#else
#define no_ubsan
#endif
#pragma warning(push)
#pragma warning(disable : 4244) // loss of data warning
#pragma warning(disable : 4101) // unreferenced local variable
#define STBSP_ADD_TO_FUNCTIONS no_ubsan
#define MD_FUNCTION no_ubsan
#include "md.h"
#include "md.c"
#pragma warning(pop)
@ -51,7 +59,7 @@ MD_String8 asset_file_path(MD_String8 filename) {
}
char *nullterm(MD_String8 s) {
char *to_return = malloc(s.size + 1);
char *to_return = MD_ArenaPush(cg_arena, s.size + 1);
memcpy(to_return, s.str, s.size);
to_return[s.size] = '\0';
return to_return;
@ -154,7 +162,7 @@ int main(int argc, char **argv)
MD_String8 filepath = ChildValue(node, MD_S8Lit("filepath"));
filepath = asset_file_path(filepath);
assert(filepath.str != 0); // MD_S8Fmt(cg_arena, "No filepath specified for sound '%.*s'", MD_S8VArg(node->string)));
FILE *asset_file = fopen(filepath.str, "r");
FILE *asset_file = fopen(nullterm(filepath), "r");
assert(asset_file); // MD_S8Fmt(cg_arena, "Could not open filepath %.*s for asset '%.*s'", MD_S8VArg(filepath), MD_S8VArg(node->string)));
fclose(asset_file);
@ -167,7 +175,7 @@ int main(int argc, char **argv)
MD_String8 filepath = ChildValue(node, MD_S8Lit("filepath"));
filepath = asset_file_path(filepath);
assert(filepath.str != 0); // , MD_S8Fmt(cg_arena, "No filepath specified for image '%.*s'", MD_S8VArg(node->string)));
FILE *asset_file = fopen(filepath.str, "r");
FILE *asset_file = fopen(nullterm(filepath), "r");
assert(asset_file); // , MD_S8Fmt(cg_arena, "Could not open filepath %.*s for asset '%.*s'", MD_S8VArg(filepath), MD_S8VArg(node->string)));
fclose(asset_file);

@ -36,7 +36,7 @@ thirdparty\sokol-shdc.exe --input quad.glsl --output gen\quad-sapp.glsl.h --slan
@REM metadesk codegen
@REM cl /Ithirdparty /W3 /Zi /WX codegen.c || goto :error
zig -Ithirdparty -gfull -gcodeview codegen.c -o codegen.exe || goto error
zig cc -Ithirdparty -gfull -gcodeview codegen.c -o codegen.exe || goto error
codegen || goto :error
@REM cl /Ithirdparty /Igen /W3 /Zi /WX maketraining.c || goto :error

@ -165,19 +165,26 @@ PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC):
#define STBSP__ASAN
#endif
#ifdef STB_SPRINTF_STATIC
#define STBSP__PUBLICDEC static
#define STBSP__PUBLICDEF static STBSP__ASAN
#define STBSP__NEW_PUBLICDEF static STBSP__ASAN
#else
#ifdef __cplusplus
#define STBSP__PUBLICDEC extern "C"
#define STBSP__PUBLICDEF extern "C" STBSP__ASAN
#define STBSP__NEW_PUBLICDEF extern "C" STBSP__ASAN
#else
#define STBSP__PUBLICDEC extern
#define STBSP__PUBLICDEF STBSP__ASAN
#define STBSP__NEW_PUBLICDEF STBSP__ASAN
#endif
#endif
#ifndef STBSP_ADD_TO_FUNCTIONS
#define STBSP_ADD_TO_FUNCTIONS
#endif
#define STBSP__PUBLICDEF STBSP_ADD_TO_FUNCTIONS STBSP__NEW_PUBLICDEF
#include <stdarg.h> // for va_list()
#include <stddef.h> // size_t, ptrdiff_t

@ -1114,12 +1114,12 @@ static size_t stbds_siphash_bytes(void *p, size_t len, size_t seed)
}
#if defined(__clang__)
#define no_ubsan_overflow __attribute__((no_sanitize("undefined")))
#define no_ubsan __attribute__((no_sanitize("undefined")))
#else
#define no_ubsan_overflow
#define no_ubsan
#endif
size_t no_ubsan_overflow stbds_hash_bytes(void *p, size_t len, size_t seed)
size_t no_ubsan stbds_hash_bytes(void *p, size_t len, size_t seed)
{
#ifdef STBDS_SIPHASH_2_4
return stbds_siphash_bytes(p,len,seed);

Loading…
Cancel
Save