Module Name:    src
Committed By:   christos
Date:           Mon Feb 10 16:29:30 UTC 2014

Modified Files:
        src/lib/libc/inet: inet_ntop.c

Log Message:
PR/48585: Henning Petersen: Always set errno when returning NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/inet/inet_ntop.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/inet/inet_ntop.c
diff -u src/lib/libc/inet/inet_ntop.c:1.9 src/lib/libc/inet/inet_ntop.c:1.10
--- src/lib/libc/inet/inet_ntop.c:1.9	Tue Mar 20 13:08:13 2012
+++ src/lib/libc/inet/inet_ntop.c	Mon Feb 10 11:29:30 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $	*/
+/*	$NetBSD: inet_ntop.c,v 1.10 2014/02/10 16:29:30 christos Exp $	*/
 
 /*
  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -22,7 +22,7 @@
 #if 0
 static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp";
 #else
-__RCSID("$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $");
+__RCSID("$NetBSD: inet_ntop.c,v 1.10 2014/02/10 16:29:30 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -189,7 +189,7 @@ inet_ntop6(const u_char *src, char *dst,
 		/* Are we following an initial run of 0x00s or any real hex? */
 		if (i != 0) {
 			if (tp + 1 >= ep)
-				return (NULL);
+				goto out;
 			*tp++ = ':';
 		}
 		/* Is this address an encapsulated IPv4? */
@@ -197,36 +197,37 @@ inet_ntop6(const u_char *src, char *dst,
 		    (best.len == 6 ||
 		    (best.len == 7 && words[7] != 0x0001) ||
 		    (best.len == 5 && words[5] == 0xffff))) {
-			if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))
-				return (NULL);
+			if (!inet_ntop4(src + 12, tp, (socklen_t)(ep - tp)))
+				goto out;
 			tp += strlen(tp);
 			break;
 		}
 		advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
 		if (advance <= 0 || advance >= ep - tp)
-			return (NULL);
+			goto out;
 		tp += advance;
 	}
 	/* Was it a trailing run of 0x00's? */
 	if (best.base != -1 && (best.base + best.len) == 
 	    (NS_IN6ADDRSZ / NS_INT16SZ)) {
 		if (tp + 1 >= ep)
-			return (NULL);
+			goto out;
 		*tp++ = ':';
 	}
 	if (tp + 1 >= ep)
-		return (NULL);
+		goto out;
 	*tp++ = '\0';
 
 	/*
 	 * Check for overflow, copy, and we're done.
 	 */
-	if ((size_t)(tp - tmp) > size) {
-		errno = ENOSPC;
-		return (NULL);
-	}
+	if ((size_t)(tp - tmp) > size)
+		goto out;
 	strlcpy(dst, tmp, size);
 	return (dst);
+out:
+	errno = ENOSPC;
+	return NULL;
 }
 
 /*! \file */

Reply via email to