From 7df5e2a15f784ab786f56ca25d739c8b546ccde8 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 22 Jun 2023 23:37:54 -0400 Subject: [PATCH] libcdecl: Simplify cdecl__advance. It seems unnecessary to set the dst pointer to null here, nothing cares if this pointer is null or not null, only the length matters. --- src/output.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/output.c b/src/output.c index 27921ab..cf5e2ff 100644 --- a/src/output.c +++ b/src/output.c @@ -24,15 +24,14 @@ #include "specstr.h" +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + size_t cdecl__advance(struct output_state *dst, size_t amount) { - if (amount >= dst->dstlen) { - dst->dstlen = 0; - dst->dst = 0; - } else { - dst->dst += amount; - dst->dstlen -= amount; - } + size_t x = MIN(amount, dst->dstlen); + + dst->dst += x; + dst->dstlen -= x; return amount; } -- 2.43.2