Date: Fri, 26 May 2017 03:27:06 +0000 (UTC) From: Marcelo Araujo <araujo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318915 - head/usr.sbin/ypldap Message-ID: <201705260327.v4Q3R6Uw078365@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: araujo Date: Fri May 26 03:27:06 2017 New Revision: 318915 URL: https://svnweb.freebsd.org/changeset/base/318915 Log: Simplify parseval() by allocating a buffer the size of the input string, which will always be big enough to hold the output string. Obtained from: OpenBSD (revision 1.36) Modified: head/usr.sbin/ypldap/aldap.c Modified: head/usr.sbin/ypldap/aldap.c ============================================================================== --- head/usr.sbin/ypldap/aldap.c Fri May 26 02:30:26 2017 (r318914) +++ head/usr.sbin/ypldap/aldap.c Fri May 26 03:27:06 2017 (r318915) @@ -1212,30 +1212,19 @@ char * parseval(char *p, size_t len) { char hex[3]; - char *cp = p, *buffer, *newbuffer; - size_t size, newsize, i, j; + char *buffer; + size_t i, j; - size = 50; - if ((buffer = calloc(1, size)) == NULL) + if ((buffer = calloc(1, len + 1)) == NULL) return NULL; for (i = j = 0; j < len; i++) { - if (i >= size) { - newsize = size + 1024; - if ((newbuffer = realloc(buffer, newsize)) == NULL) { - free(buffer); - return (NULL); - } - buffer = newbuffer; - size = newsize; - } - - if (cp[j] == '\\') { - strlcpy(hex, cp + j + 1, sizeof(hex)); + if (p[j] == '\\') { + strlcpy(hex, p + j + 1, sizeof(hex)); buffer[i] = (char)strtoumax(hex, NULL, 16); j += 3; } else { - buffer[i] = cp[j]; + buffer[i] = p[j]; j++; } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705260327.v4Q3R6Uw078365>