Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/inet PR/48585: Henning Petersen: Always set errno w...



details:   https://anonhg.NetBSD.org/src/rev/d9c23882d15c
branches:  trunk
changeset: 326660:d9c23882d15c
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Feb 10 16:29:30 2014 +0000

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

diffstat:

 lib/libc/inet/inet_ntop.c |  25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diffs (74 lines):

diff -r 2b595c76d3e1 -r d9c23882d15c lib/libc/inet/inet_ntop.c
--- a/lib/libc/inet/inet_ntop.c Mon Feb 10 11:23:14 2014 +0000
+++ b/lib/libc/inet/inet_ntop.c Mon Feb 10 16:29:30 2014 +0000
@@ -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 @@
                /* 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 @@
                    (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 */



Home | Main Index | Thread Index | Old Index