diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-10-28 01:55:10 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-10-28 01:55:10 +0000 |
commit | 9d75336e38b698968c6a5f09aafa944824f6c1c0 (patch) | |
tree | aec30c2e1b01f6dc4d7f8f7705b7edff1736cfc2 /epan/inet_ntop.c | |
parent | 1b526aa894490d5dfe379a7e6ff6163378c715e5 (diff) |
Clean up another signed vs. unsigned comparison warning - if
"snprintf()" returns a negative number, that's an error, and we assume
"errno" was set and return NULL, otherwise we cast its return value to
"size_t" and compare it with the size of the buffer we were given, and,
if it was bigger, we know that "snprintf()" didn't generate all the
characters it could be cause they wouldn't have fit, so we set "errno"
to ENOSPC and return NULL.
svn path=/trunk/; revision=4095
Diffstat (limited to 'epan/inet_ntop.c')
-rw-r--r-- | epan/inet_ntop.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/epan/inet_ntop.c b/epan/inet_ntop.c index 983d344ee1..0f50bc761a 100644 --- a/epan/inet_ntop.c +++ b/epan/inet_ntop.c @@ -20,7 +20,7 @@ #endif #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$Id: inet_ntop.c,v 1.1 2000/10/14 04:31:26 gram Exp $"; +static char rcsid[] = "$Id: inet_ntop.c,v 1.2 2001/10/28 01:55:10 guy Exp $"; #endif /* LIBC_SCCS and not lint */ #ifdef HAVE_SYS_PARAM_H @@ -126,8 +126,12 @@ inet_ntop4(src, dst, size) { static const char fmt[] = "%u.%u.%u.%u"; char tmp[sizeof "255.255.255.255"]; + int nprinted; - if (snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]) > size) { + nprinted = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]); + if (nprinted < 0) + return (NULL); /* we assume "errno" was set by "snprintf()" */ + if ((size_t)nprinted > size) { errno = ENOSPC; return (NULL); } |