From 77ade8d20906fe9ca2cf6788ff1e1437e0912868 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 1 Jun 2026 19:07:14 +0200 Subject: Second commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- memcheck.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'memcheck.c') diff --git a/memcheck.c b/memcheck.c index b119fad..7f788a3 100644 --- a/memcheck.c +++ b/memcheck.c @@ -17,6 +17,16 @@ #include +#if defined(__GNUC__) +# pragma GCC diagnostic ignored "-Wpadded" +#endif +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +# pragma clang diagnostic ignored "-Wcomma" +# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is currently exceptionally stupid */ +#endif + + enum alloctype { ALLOCTYPE_REALLOC, ALLOCTYPE_MMAP @@ -150,7 +160,8 @@ fail: static void memcheck_print_backtrace(struct backtrace *backtrace, const char *indent) { - int saved_errno = errno, lineno; + int saved_errno = errno; + int lineno = 0; /* initialised to silence compiler */ char *debuginfo_path = NULL; Dwarf_Addr ip; Dwfl_Callbacks callbacks; @@ -172,6 +183,8 @@ memcheck_print_backtrace(struct backtrace *backtrace, const char *indent) callbacks.find_debuginfo = dwfl_standard_find_debuginfo; callbacks.debuginfo_path = &debuginfo_path; + dwfl = dwfl_begin(&callbacks); + if (dwfl) { if (dwfl_linux_proc_report(dwfl, getpid()) || dwfl_report_end(dwfl, NULL, NULL)) { @@ -211,10 +224,12 @@ memcheck_print_backtrace(struct backtrace *backtrace, const char *indent) #endif -#if defined(__GNUC__) +#if defined(__clang__) +__attribute__((__format__(__printf__, 1, 2))) +#elif defined(__GNUC__) __attribute__((__format__(__gnu_printf__, 1, 2))) #endif -static void +static _Noreturn void memcheck_errorf(const char *fmt, ...) { va_list ap; @@ -610,6 +625,7 @@ memcheck_check_memleaks(void) { struct allocinfo *leak; size_t i, count = 0; + int first = 1; memleak_exclusion = 1; for (i = 0; i < nallocs; i++) { leak = &allocs[i]; @@ -625,6 +641,10 @@ memcheck_check_memleaks(void) leak = &allocs[i]; if (leak->dont_track) continue; + if (first) + first = 0; + else + dprintf(STDERR_FILENO, "\n"); memcheck_print_backtrace(leak->backtrace, "\t"); } #endif -- cgit v1.3.1