From 698159c01a9d99382406a6521df5c5fd292b05ec Mon Sep 17 00:00:00 2001 From: kris Date: Mon, 16 Jul 2001 03:55:47 +0000 Subject: Avoid a compile-time format string warning Obtained from: NetBSD MFC After: 1 week --- lib/libc/net/ns_addr.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/libc/net/ns_addr.c b/lib/libc/net/ns_addr.c index 553d31e..f26ed91 100644 --- a/lib/libc/net/ns_addr.c +++ b/lib/libc/net/ns_addr.c @@ -105,7 +105,6 @@ Field(buf, out, len) register char *bp = buf; int i, ibase, base16 = 0, base10 = 0, clen = 0; int hb[6], *hp; - char *fmt; /* * first try 2-273#2-852-151-014#socket @@ -173,13 +172,11 @@ Field(buf, out, len) *--bp = 0; /* Ends Loop */ } if (base16) { - fmt = "%3x"; ibase = 4096; } else if (base10 == 0 && *buf == '0') { - fmt = "%3o"; ibase = 512; } else { - fmt = "%3d"; + base10 = 1; ibase = 1000; } @@ -190,13 +187,19 @@ Field(buf, out, len) bp = clen + buf - 3; hp = hb + i - 1; - while (hp > hb) { - (void)sscanf(bp, fmt, hp); - bp[0] = 0; - hp--; - bp -= 3; + while (hp >= hb) { + if (base16) + (void)sscanf(bp, "%3x", hp); + else if (base10) + (void)sscanf(bp, "%3d", hp); + else + (void)sscanf(bp, "%3o", hp); + if (hp > hb) { + bp[0] = 0; + hp--; + bp -= 3; + } } - (void)sscanf(buf, fmt, hp); cvtbase((long)ibase, 256, hb, i, out, len); } -- cgit v1.1