diff options
author | delphij <delphij@FreeBSD.org> | 2009-06-23 23:34:46 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2009-06-23 23:34:46 +0000 |
commit | d9ff11dbb2363bd47152e57983b6866e6c7cf92a (patch) | |
tree | 6e01631ee7cc34b3aca87c483a9fb1a4d666ba71 /usr.bin | |
parent | 08ae7d200efa5ab9e869687d34f8a484ab92a756 (diff) | |
download | FreeBSD-src-d9ff11dbb2363bd47152e57983b6866e6c7cf92a.zip FreeBSD-src-d9ff11dbb2363bd47152e57983b6866e6c7cf92a.tar.gz |
Use strlcpy() instead of manually setting the last byte of the array to \0.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/arch.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/usr.bin/make/arch.c b/usr.bin/make/arch.c index d8206e0..90801cd 100644 --- a/usr.bin/make/arch.c +++ b/usr.bin/make/arch.c @@ -583,8 +583,7 @@ ArchArchiveNext(struct arfile *ar) * looks like a member - get name by stripping trailing spaces * and NUL terminating. */ - strncpy(ar->sname, ar->hdr.ar_name, AR_NAMSIZ); - ar->sname[AR_NAMSIZ] = '\0'; + strlcpy(ar->sname, ar->hdr.ar_name, AR_NAMSIZ + 1); for (ptr = ar->sname + AR_NAMSIZ; ptr > ar->sname; ptr--) if (ptr[-1] != ' ') break; @@ -595,8 +594,7 @@ ArchArchiveNext(struct arfile *ar) * Parse the size. All entries need to have a size. Be careful * to not allow buffer overruns. */ - strncpy(buf, ar->hdr.ar_size, sizeof(ar->hdr.ar_size)); - buf[sizeof(ar->hdr.ar_size)] = '\0'; + strlcpy(buf, ar->hdr.ar_size, sizeof(ar->hdr.ar_size) + 1); errno = 0; ar->size = strtoumax(buf, &end, 10); @@ -650,8 +648,7 @@ ArchArchiveNext(struct arfile *ar) * Now parse the modification date. Be careful to not overrun * buffers. */ - strncpy(buf, ar->hdr.ar_date, sizeof(ar->hdr.ar_date)); - buf[sizeof(ar->hdr.ar_date)] = '\0'; + strlcpy(buf, ar->hdr.ar_date, sizeof(ar->hdr.ar_date) + 1); errno = 0; ar->time = (int64_t)strtoll(buf, &end, 10); @@ -965,8 +962,7 @@ ArchStatMember(const char *archive, const char *member, Boolean hash) if (member != NULL && strlen(member) > AR_NAMSIZ) { /* Try truncated name */ - strncpy(copy, member, AR_NAMSIZ); - copy[AR_NAMSIZ] = '\0'; + strlcpy(copy, member, AR_NAMSIZ + 1); if ((he = Hash_FindEntry(&ar->members, copy)) != NULL) return (*(int64_t *)Hash_GetValue(he)); |