[Git][NTPsec/ntpsec][master] 2 commits: ntp_control: Clean up ctl_putrefid()

Gary E. Miller gitlab at mg.gitlab.com
Wed Jan 30 03:04:47 UTC 2019


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
c1d4f866 by Gary E. Miller at 2019-01-30T03:02:58Z
ntp_control: Clean up ctl_putrefid()

- - - - -
44011f5d by Gary E. Miller at 2019-01-30T03:04:15Z
gitignore: Ignore attic/clock

An optional build product.

- - - - -


2 changed files:

- .gitignore
- ntpd/ntp_control.c


Changes:

=====================================
.gitignore
=====================================
@@ -2,3 +2,4 @@
 .waf*
 *.pyc
 build
+attic/clock


=====================================
ntpd/ntp_control.c
=====================================
@@ -1395,38 +1395,32 @@ ctl_putadr(
  */
 static void
 ctl_putrefid(
-	const char *	tag,
-	refid_t		refid
-	)
+        const char *    tag,
+        refid_t         refid
+)
 {
-	char	output[16];
-	char *	optr;
-	char *	oplim;
-	unsigned char *	iptr;
-	unsigned char *	iplim;
-	char *	past_eq = NULL;
-
-	optr = output;
-	oplim = output + sizeof(output);
-	while (optr < oplim && '\0' != *tag)
-		*optr++ = *tag++;
-	if (optr < oplim) {
-		*optr++ = '=';
-		past_eq = optr;
-	}
-	if (!(optr < oplim))
-		return;
-	iptr = refid;
-	iplim = iptr + REFIDLEN;
-	for ( ; optr < oplim && iptr < iplim && '\0' != *iptr;
-	     iptr++, optr++)
-		if (isprint((int)*iptr))
-			*optr = *iptr;
-		else
-			*optr = '.';
-	if (!(optr <= oplim))
-		optr = past_eq;
-	ctl_putdata(output, (unsigned int)(optr - output), false);
+        char    output[16];
+        char    buf[REFIDLEN + 1];
+        int i;
+
+        strlcpy(output, tag, sizeof(output));
+        strlcat(output, "=", sizeof(output));
+
+        /* grab the refid */
+        strlcpy(buf, refid, sizeof(buf));
+
+        /* be sure it is printable, how can it not be? */
+        for (i = 0; i < REFIDLEN; i++) {
+            if ('\0' == buf[i]) {
+                break;
+            }
+            if (!isprint(buf[i])) {
+                buf[i] = '.';
+            }
+        }
+
+        strlcat(output, buf, sizeof(output));
+        ctl_putdata(output, strlen(output), false);
 }
 
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/d0984444c53ed3ed4e7ab546752ac810f254981e...44011f5db00d64b6166515a5efe35ae6bd77bccd

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/d0984444c53ed3ed4e7ab546752ac810f254981e...44011f5db00d64b6166515a5efe35ae6bd77bccd
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20190130/c4dd1e44/attachment-0001.html>


More information about the vc mailing list