From 7fd570ff6f4b5ac34d88f49dc6977b58d9773195 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 12 Jul 2021 20:04:37 +0100 Subject: [PATCH] Change all `map_handle_err(map_free())` conditionals to `UNLIKELY` (`ifU()`), as it is unlikely an unmap will fail on a map that has already been established successfully. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for naka's current commit: Small blessing − 小吉 --- src/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 7370ba4..61d4038 100644 --- a/src/main.c +++ b/src/main.c @@ -114,7 +114,7 @@ static int map_haystacks(const char* const * h, map_t maps[pOUT]) maps-=1; ERROR("Failed to map file `%s', rolling back %lu maps. (erp: %p, prev: %p)", path, d, c, maps); while( d --> 0 ) - if(!map_handle_err(map_free(* (--maps)))) WARN("Failed to free map at %p (in %lu unwind)", maps, d); + ifU(!map_handle_err(map_free(* (--maps)))) WARN("Failed to free map at %p (in %lu unwind)", maps, d); return 0; } d+=1; @@ -151,7 +151,7 @@ inv_args: TRACE("Attempting to map %lu haystacks", hsn); if(!map_haystacks((const char**)(argv+1), haystacks)) { // Unmap needle before return. - if(!map_handle_err(map_free(needle))) WARN("Failed to unmap needle before exiting after failed haystack maps"); + ifU(!map_handle_err(map_free(needle))) WARN("Failed to unmap needle before exiting after failed haystack maps"); return PROG_RET_MAP_HAYSTACK_FAILED; } @@ -177,11 +177,11 @@ inv_args: for(int i=0;i<(int)hsn;i++) { INFO("Unmapping haystack haystack file `%s' (#%d) (map addr %p)", argv[i+1], i+1, haystacks+i); - if(!map_handle_err(map_free(haystacks[i]))) m_rval = !m_rval ? PROG_RET_UNMAP_HAYSTACK_N_FAILED(i+1) : m_rval; + ifU(!map_handle_err(map_free(haystacks[i]))) m_rval = !m_rval ? PROG_RET_UNMAP_HAYSTACK_N_FAILED(i+1) : m_rval; } TRACE("Unmap haystacks ended with main rval: %d", m_rval); INFO("Unmapping needle file `%s'", *argv); - if(!map_handle_err(map_free(needle))) m_rval = !m_rval ? PROG_RET_UNMAP_NEEDLE_FAILED : m_rval; + ifU(!map_handle_err(map_free(needle))) m_rval = !m_rval ? PROG_RET_UNMAP_NEEDLE_FAILED : m_rval; TRACE("main end: rval %d", m_rval); return m_rval; }