From c4f8f000273f029e9aebc8eb305a21975c853786 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 9 Aug 2017 11:10:38 +0300 Subject: Do not call BCOPY and BZERO if size is zero * dbg_mlc.c (GC_debug_strndup): Do not call BCOPY() if elements count is zero. * dbg_mlc.c (GC_debug_realloc): Likewise. * finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (ensure_toggleref_capacity): Likewise. * malloc.c [REDIRECT_MALLOC && !strndup] (strndup): Likewise. * mallocx.c (GC_strndup): Likewise. * misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED] (GC_get_prof_stats): Likewise. * os_dep.c [SAVE_CALL_CHAIN && GC_HAVE_BUILTIN_BACKTRACE] (GC_save_callers): Likewise. * reclaim.c (GC_print_all_errors): Likewise. * malloc.c (GC_free): Do not call BZERO() if elements count is zero. * malloc.c [THREADS] (GC_free_inner): Likewise. * reclaim.c (GC_print_all_errors): Likewise. * misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED && THREADS] (GC_get_prof_stats_unsafe): Do not call fill_prof_stats() and BCOPY() if stats_sz is zero. --- dbg_mlc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'dbg_mlc.c') diff --git a/dbg_mlc.c b/dbg_mlc.c index 724d9cff..4edeeefd 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -760,7 +760,8 @@ GC_API GC_ATTR_MALLOC char * GC_CALL GC_debug_strndup(const char *str, # endif return NULL; } - BCOPY(str, copy, len); + if (len > 0) + BCOPY(str, copy, len); copy[len] = '\0'; return copy; } @@ -973,7 +974,8 @@ GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS) # else old_sz = ((oh *)base) -> oh_sz; # endif - BCOPY(p, result, old_sz < lb ? old_sz : lb); + if (old_sz > 0) + BCOPY(p, result, old_sz < lb ? old_sz : lb); GC_debug_free(p); } return(result); -- cgit v1.2.1