[llvm] r291256 - Use %z for size_t and avoid deprecated string functions
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 6 10:22:18 PST 2017
Author: rnk
Date: Fri Jan 6 12:22:18 2017
New Revision: 291256
URL: http://llvm.org/viewvc/llvm-project?rev=291256&view=rev
Log:
Use %z for size_t and avoid deprecated string functions
This usage of strcpy and snprintf was certainly safe, but using them
sets off various deprecation and lint warnings. Easier to just write the
belt and suspenders version.
Modified:
llvm/trunk/lib/Support/TarWriter.cpp
Modified: llvm/trunk/lib/Support/TarWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/TarWriter.cpp?rev=291256&r1=291255&r2=291256&view=diff
==============================================================================
--- llvm/trunk/lib/Support/TarWriter.cpp (original)
+++ llvm/trunk/lib/Support/TarWriter.cpp Fri Jan 6 12:22:18 2017
@@ -87,7 +87,7 @@ static void computeChecksum(UstarHeader
unsigned Chksum = 0;
for (size_t I = 0; I < sizeof(Hdr); ++I)
Chksum += reinterpret_cast<uint8_t *>(&Hdr)[I];
- sprintf(Hdr.Checksum, "%06o", Chksum);
+ snprintf(Hdr.Checksum, sizeof(Hdr.Checksum), "%06o", Chksum);
}
// Create a tar header and write it to a given output stream.
@@ -98,7 +98,7 @@ static void writePaxHeader(raw_fd_ostrea
// Create a 512-byte header.
UstarHeader Hdr = {};
- sprintf(Hdr.Size, "%011lo", PaxAttr.size());
+ snprintf(Hdr.Size, sizeof(Hdr.Size), "%011zo", PaxAttr.size());
Hdr.TypeFlag = 'x'; // PAX magic
memcpy(Hdr.Magic, "ustar", 6); // Ustar magic
computeChecksum(Hdr);
@@ -114,8 +114,8 @@ static void writePaxHeader(raw_fd_ostrea
static void writeUstarHeader(raw_fd_ostream &OS, StringRef Path, size_t Size) {
UstarHeader Hdr = {};
memcpy(Hdr.Name, Path.data(), Path.size());
- strcpy(Hdr.Mode, "0000664");
- sprintf(Hdr.Size, "%011lo", Size);
+ memcpy(Hdr.Mode, "0000664", 8);
+ snprintf(Hdr.Size, sizeof(Hdr.Size), "%011zo", Size);
memcpy(Hdr.Magic, "ustar", 6);
computeChecksum(Hdr);
OS << StringRef(reinterpret_cast<char *>(&Hdr), sizeof(Hdr));
More information about the llvm-commits
mailing list