]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Fix fencepost error in fn_printn() which would return a truncation
authorfenner <fenner>
Mon, 21 Apr 2003 16:59:52 +0000 (16:59 +0000)
committerfenner <fenner>
Mon, 21 Apr 2003 16:59:52 +0000 (16:59 +0000)
 indication if the last byte of the counted string was the last
 byte captured.

util.c

diff --git a/util.c b/util.c
index c99bcb55c73d1db3470375faeeaeb0a94f5a5e82..ad7e3fdeb1e1d909a55c0600c8f8f6226bfba957 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.84 2003-03-04 08:53:26 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.85 2003-04-21 16:59:52 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -85,15 +85,10 @@ int
 fn_printn(register const u_char *s, register u_int n,
          register const u_char *ep)
 {
-       register int ret;
        register u_char c;
 
-       ret = 1;                        /* assume truncated */
-       while (ep == NULL || s < ep) {
-               if (n-- <= 0) {
-                       ret = 0;
-                       break;
-               }
+       while (n > 0 && (ep == NULL || s < ep)) {
+               n--;
                c = *s++;
                if (!isascii(c)) {
                        c = toascii(c);
@@ -106,7 +101,7 @@ fn_printn(register const u_char *s, register u_int n,
                }
                putchar(c);
        }
-       return(ret);
+       return (n == 0) ? 0 : 1;
 }
 
 /*