X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/0a49a7a4f1090b6f1ce1d0f9d969804c9226b53e..4e19eed51a7f777e1e18b60c636e0c9bfb82c23b:/src/src/auths/xtextencode.c diff --git a/src/src/auths/xtextencode.c b/src/src/auths/xtextencode.c index fd367a5f4..75be18161 100644 --- a/src/src/auths/xtextencode.c +++ b/src/src/auths/xtextencode.c @@ -1,11 +1,11 @@ -/* $Cambridge: exim/src/src/auths/xtextencode.c,v 1.5 2009/11/16 19:50:38 nm4 Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2009 */ +/* Copyright (c) The Exim Maintainers 2022 */ +/* Copyright (c) University of Cambridge 1995 - 2018 */ /* See the file NOTICE for conditions of use and distribution. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ #include "../exim.h" @@ -29,35 +29,14 @@ Returns: a pointer to the zero-terminated xtext string, which uschar * auth_xtextencode(uschar *clear, int len) { -uschar *code; -uschar *p = (uschar *)clear; -uschar *pp; -int c = len; -int count = 1; -register int x; - -/* We have to do a prepass to find out how many specials there are, -in order to get the right amount of store. */ - -while (c -- > 0) - count += ((x = *p++) < 33 || x > 127 || x == '+' || x == '=')? 3 : 1; - -pp = code = store_get(count); - -p = (uschar *)clear; -c = len; -while (c-- > 0) - { - if ((x = *p++) < 33 || x > 127 || x == '+' || x == '=') - { - sprintf(CS pp, "+%.02x", x); /* There's always room */ - pp += 3; - } - else *pp++ = x; - } - -*pp = 0; -return code; +gstring * g = NULL; +for(uschar ch; len > 0; len--, clear++) + g = (ch = *clear) < 33 || ch > 126 || ch == '+' || ch == '=' + ? string_fmt_append(g, "+%.02X", ch) + : string_catn(g, clear, 1); +gstring_release_unused(g); +return string_from_gstring(g); } + /* End of xtextencode.c */