[Git][NTPsec/ntpsec][master] ntp_control: Clean up ctl_putadr()

Gary E. Miller gitlab at mg.gitlab.com
Wed Jan 30 00:44:31 UTC 2019


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


Commits:
d0984444 by Gary E. Miller at 2019-01-30T00:44:02Z
ntp_control: Clean up ctl_putadr()

- - - - -


1 changed file:

- ntpd/ntp_control.c


Changes:

=====================================
ntpd/ntp_control.c
=====================================
@@ -1372,28 +1372,21 @@ ctl_putadr(
 	sockaddr_u *addr
 	)
 {
-	char *cp;
 	const char *cq;
 	char buffer[200];
 
-	cp = buffer;
-	cq = tag;
-	while (*cq != '\0' && cp < buffer + sizeof(buffer) - 1)
-		*cp++ = *cq++;
-
-	*cp++ = '=';
-	if (NULL == addr) {
-		if (NULL == refid)
-			cq = "";
-		else
-			cq = refid_dump(*refid, 1);
-	}
-	else
+	strlcpy(buffer, tag, sizeof(buffer));
+	strlcat(buffer, "=", sizeof(buffer));
+	if (NULL != addr) {
 		cq = socktoa(addr);
-	INSIST((cp - buffer) < (int)sizeof(buffer));
-	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "%s", cq);
-	cp += strlen(cp);
-	ctl_putdata(buffer, (unsigned)(cp - buffer), false);
+        } else if (NULL != refid) {
+		cq = refid_dump(*refid, 1);
+	} else {
+		cq = "0.0.0.0";
+        }
+
+	strlcat(buffer, cq, sizeof(buffer));
+	ctl_putdata(buffer, strlen(buffer), false);
 }
 
 



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

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/d0984444c53ed3ed4e7ab546752ac810f254981e
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/547e86d2/attachment-0001.html>


More information about the vc mailing list