From 4af403d5c4c5eca170a2128508210ed38dd56ae2 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 3 May 2021 18:24:40 -0700 Subject: [PATCH] ICU-21588 Fix strncpy warning --- icu4c/source/tools/genrb/reslist.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/icu4c/source/tools/genrb/reslist.cpp b/icu4c/source/tools/genrb/reslist.cpp index 389ad19b38b..b9e0d7d8c43 100644 --- a/icu4c/source/tools/genrb/reslist.cpp +++ b/icu4c/source/tools/genrb/reslist.cpp @@ -954,11 +954,7 @@ void SRBRoot::write(const char *outputDir, const char *outputPkg, if (writtenFilename) { int32_t off = 0, len = 0; if (outputDir) { - len = (int32_t)uprv_strlen(outputDir); - if (len > writtenFilenameLen) { - len = writtenFilenameLen; - } - uprv_strncpy(writtenFilename, outputDir, len); + uprv_strncpy(writtenFilename, outputDir, writtenFilenameLen); } if (writtenFilenameLen -= len) { off += len; @@ -977,14 +973,10 @@ void SRBRoot::write(const char *outputDir, const char *outputPkg, if (len > writtenFilenameLen) { len = writtenFilenameLen; } - uprv_strncpy(writtenFilename + off, fLocale, len); + uprv_strncpy(writtenFilename + off, fLocale, writtenFilenameLen - off); if (writtenFilenameLen -= len) { off += len; - len = 5; - if (len > writtenFilenameLen) { - len = writtenFilenameLen; - } - uprv_strncpy(writtenFilename + off, ".res", len); + uprv_strncpy(writtenFilename + off, ".res", writtenFilenameLen - off); } } }