Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Apr 2016 17:57:17 +0000 (UTC)
From:      Garrett Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r298750 - head/usr.sbin/bsnmpd/tools/libbsnmptools
Message-ID:  <201604281757.u3SHvHeU018636@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Thu Apr 28 17:57:17 2016
New Revision: 298750
URL: https://svnweb.freebsd.org/changeset/base/298750

Log:
  Use a better idiom for finding UTC prefixed timezones
  
  Instead of copy-pasting the string literal for "UTC" 3 times and using
  strlen, use a static char[3] buffer and sizeof(..).
  
  MFC after: 3 days
  X-MFC with: r298507
  Submitted by: kib
  Sponsored by: EMC / Isilon Storage Division

Modified:
  head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c

Modified: head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c
==============================================================================
--- head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c	Thu Apr 28 17:50:16 2016	(r298749)
+++ head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c	Thu Apr 28 17:57:17 2016	(r298750)
@@ -338,8 +338,9 @@ static char *
 snmp_date2asn_oid(char *str, struct asn_oid *oid)
 {
 	char *endptr, *ptr;
-	uint32_t v;
+	static const char UTC[3] = "UTC";
 	int32_t saved_errno;
+	uint32_t v;
 
 	if (snmp_suboid_append(oid, (asn_subid_t) SNMP_DATETIME_OCTETS) < 0)
 		return (NULL);
@@ -440,8 +441,8 @@ snmp_date2asn_oid(char *str, struct asn_
 
 	/* 'UTC' - optional */
 	ptr = endptr + 1;
-	if (strncmp(ptr, "UTC", strlen("UTC")) == 0)
-		ptr += strlen("UTC");
+	if (strncmp(ptr, UTC, sizeof(UTC)) == 0)
+		ptr += sizeof(UTC);
 
 	/* '+/-' */
 	if (*ptr == '-' || *ptr == '+') {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201604281757.u3SHvHeU018636>