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++;
                }
        }
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to