From f6d43c698bc42f8a17e2568f70c54b9a2023b1d8 Mon Sep 17 00:00:00 2001 From: itojun <> Date: Fri, 23 Aug 2002 16:27:31 +0000 Subject: deal with negative return value from snprintf. --- src/lib/libc/net/inet_ntop.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libc/net/inet_ntop.c b/src/lib/libc/net/inet_ntop.c index 5293e80fc0..adce61c1d4 100644 --- a/src/lib/libc/net/inet_ntop.c +++ b/src/lib/libc/net/inet_ntop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet_ntop.c,v 1.4 2002/08/19 03:01:54 itojun Exp $ */ +/* $OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Exp $ */ /* Copyright (c) 1996 by Internet Software Consortium. * @@ -20,7 +20,7 @@ #if 0 static char rcsid[] = "$From: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.4 2002/08/19 03:01:54 itojun Exp $"; +static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -88,8 +88,10 @@ inet_ntop4(src, dst, size) { static const char fmt[] = "%u.%u.%u.%u"; char tmp[sizeof "255.255.255.255"]; + int l; - if (snprintf(tmp, size, fmt, src[0], src[1], src[2], src[3]) >= size) { + l = snprintf(tmp, size, fmt, src[0], src[1], src[2], src[3]); + if (l <= 0 || l >= size) { errno = ENOSPC; return (NULL); } -- cgit v1.2.3-55-g6feb