[Git][NTPsec/ntpsec][master] ntp_control: Cleanup ctl_putrefid()

Gary E. Miller gitlab at mg.gitlab.com
Thu Jan 31 00:32:05 UTC 2019


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


Commits:
90c32dd0 by Gary E. Miller at 2019-01-31T00:31:11Z
ntp_control: Cleanup ctl_putrefid()

All that pointer arithmetic was hard to follow.

- - - - -


1 changed file:

- ntpd/ntp_control.c


Changes:

=====================================
ntpd/ntp_control.c
=====================================
@@ -1404,34 +1404,26 @@ ctl_putrefid(
 	refid_t		refid
 	)
 {
-	char	output[16];
-	char *	optr;
-	char *	oplim;
-	char *	iptr;
-	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 = (char *)&refid;
-	iplim = iptr + sizeof(refid);
-	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[sizeof(refid) + 1];
+        char *  cp;
+        int i;
+
+        strlcpy(output, tag, sizeof(output));
+        strlcat(output, "=", sizeof(output));
+        /* refid is really a 4 byte, un-terminated, string */
+        cp = (char *)&refid;
+        /* make sure all printable */
+        for (i = 0; sizeof(refid) > i && '\0' != cp[i]; i++) {
+                if (isprint(cp[i]))
+                        buf[i] = cp[i];
+                else
+                        buf[i] = '.';
+        }
+        buf[i] = '\0';
+
+        strlcat(output, buf, sizeof(output));
+        ctl_putdata(output, strlen(output), false);
 }
 
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/90c32dd00f533d72f032c16463a0e283ad06f44e

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/90c32dd00f533d72f032c16463a0e283ad06f44e
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/20190131/85cafa7a/attachment-0001.html>


More information about the vc mailing list