From Jakub Zawadzki: Glib2 g_snprintf doesn't return -1;
authorwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 18 Mar 2009 00:03:41 +0000 (00:03 +0000)
committerwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 18 Mar 2009 00:03:41 +0000 (00:03 +0000)
Also: from me: fix an "off by 1" issue in inet_ntop_4
   which could result in a trailing character of the
   output string being truncated rather than an ENOSPC
   error being reported.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@27766 f5534014-38df-0310-8fa8-9805f1628bb7

inet_ntop.c

index e240f94b6578f31c6f2d39209812f783cc9e8dd5..31580c02c8d17b063b11bce5e0e1bd039706d6bf 100644 (file)
@@ -130,9 +130,8 @@ inet_ntop4(src, dst, size)
        int nprinted;
 
        nprinted = g_snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
-       if (nprinted < 0)
-               return (NULL);  /* we assume "errno" was set by "g_snprintf()" */
-       if ((size_t)nprinted > size) {
+        /* Note: nprinted *excludes* the trailing '\0' character */
+       if ((size_t)nprinted >= size) {
                errno = ENOSPC;
                return (NULL);
        }