[tz] [PROPOSED PATCH 2/4] Prefer memcpy to strncpy when either will do.

Paul Eggert eggert at cs.ucla.edu
Thu Aug 21 21:43:24 UTC 2014


* localtime.c (tzparse)
* zic.c (doabbr):
Use memcpy, as only nonzero bytes are being copied.
* zic.c (doabbr): Remove unnecessary test.
---
 localtime.c | 4 ++--
 zic.c       | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/localtime.c b/localtime.c
index 98faacd..67b1d78 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1148,11 +1148,11 @@ tzparse(const char *name, register struct state *const sp,
 	if ((size_t) sp->charcnt > sizeof sp->chars)
 	  return false;
 	cp = sp->chars;
-	strncpy(cp, stdname, stdlen);
+	memcpy(cp, stdname, stdlen);
 	cp += stdlen;
 	*cp++ = '\0';
 	if (dstlen != 0) {
-		strncpy(cp, dstname, dstlen);
+		memcpy(cp, dstname, dstlen);
 		*(cp + dstlen) = '\0';
 	}
 	return true;
diff --git a/zic.c b/zic.c
index 73ae17d..d622b80 100644
--- a/zic.c
+++ b/zic.c
@@ -1868,8 +1868,7 @@ doabbr(char *const abbr, const char *const format, const char *const letters,
 	} else if (isdst) {
 		strcpy(abbr, slashp + 1);
 	} else {
-		if (slashp > format)
-			strncpy(abbr, format, slashp - format);
+		memcpy(abbr, format, slashp - format);
 		abbr[slashp - format] = '\0';
 	}
 	if (!doquotes)
-- 
1.9.1



More information about the tz mailing list