From: Arran Cudbard-Bell Date: Thu, 3 Feb 2022 16:25:12 +0000 (-0500) Subject: No need to create all those temporary sbuffs if the input data is empty X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e6d1e60aa2e829a186b87331f12b413a6cc6d07;p=thirdparty%2Ffreeradius-server.git No need to create all those temporary sbuffs if the input data is empty --- diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 261e32a933e..7615ef72023 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -1693,8 +1693,15 @@ static xlat_action_t xlat_func_lpad(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, fr_sbuff_init_in(&sbuff, buff, pad_len); fr_sbuff_marker(&m_data, &sbuff); - fr_sbuff_advance(&m_data, pad_len - len); /* Mark where we want the data to go */ - fr_sbuff_move(&FR_SBUFF(&m_data), &FR_SBUFF(&sbuff), len); /* Shift the data */ + + /* + * ...nothing to move if the input + * string is empty. + */ + if (len > 0) { + fr_sbuff_advance(&m_data, pad_len - len); /* Mark where we want the data to go */ + fr_sbuff_move(&FR_SBUFF(&m_data), &FR_SBUFF(&sbuff), len); /* Shift the data */ + } if (fill_len == 1) { memset(fr_sbuff_current(&sbuff), *fill_str, fr_sbuff_ahead(&m_data));