Skip to content

Commit

Permalink
ICU-21589 Remove format-overflow warning
Browse files Browse the repository at this point in the history
1. double size one stack buffer
2. add pragma to ignore some theorical case because the array are in
   same length but some fields are shorter than the other.

ICU-21589 wrap with defined(__GNUC__)

ICU-21589 avoid clang
  • Loading branch information
FrankYFTang authored and roubert committed May 2, 2024
1 parent 6041c24 commit 1ff249b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion icu4c/source/tools/pkgdata/pkgdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,10 @@ static int32_t initializePkgDataFlags(UPKGOptions *o) {
static void createFileNames(UPKGOptions *o, const char mode, const char *version_major, const char *version, const char *libName, UBool reverseExt, UBool noVersion) {
const char* FILE_EXTENSION_SEP = uprv_strlen(pkgDataFlags[SO_EXT]) == 0 ? "" : ".";
const char* FILE_SUFFIX = pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "";
#if defined(__GNUC__) && !defined(__clang__)
_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic ignored \"-Wformat-truncation\"")
#endif

#if U_PLATFORM == U_PF_MINGW
/* MinGW does not need the library prefix when building in dll mode. */
Expand Down Expand Up @@ -1036,6 +1040,10 @@ static void createFileNames(UPKGOptions *o, const char mode, const char *version
fprintf(stdout, "# libFileName[LIB_FILE_VERSION] = %s (static)\n", libFileNames[LIB_FILE_VERSION]);
}
}
#if defined(__GNUC__) && !defined(__clang__)
_Pragma("GCC diagnostic pop")
#endif

}

/* Create the symbolic links for the final library file. */
Expand Down Expand Up @@ -1132,7 +1140,7 @@ static int32_t pkg_createSymLinks(const char *targetDir, UBool specialHandling)

static int32_t pkg_installLibrary(const char *installDir, const char *targetDir, UBool noVersion) {
int32_t result = 0;
char cmd[SMALL_BUFFER_MAX_SIZE];
char cmd[SMALL_BUFFER_MAX_SIZE * 2];

auto ret = snprintf(cmd,
sizeof(cmd),
Expand Down Expand Up @@ -1309,11 +1317,19 @@ static int32_t pkg_archiveLibrary(const char *targetDir, const char *version, UB
* archive file suffix is the same, then the final library needs to be archived.
*/
if (uprv_strcmp(pkgDataFlags[SOBJ_EXT], pkgDataFlags[SO_EXT]) != 0 && uprv_strcmp(pkgDataFlags[A_EXT], pkgDataFlags[SO_EXT]) == 0) {
#if defined(__GNUC__) && !defined(__clang__)
_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic ignored \"-Wformat-truncation\"")
#endif

snprintf(libFileNames[LIB_FILE_VERSION], sizeof(libFileNames[LIB_FILE_VERSION]), "%s%s%s.%s",
libFileNames[LIB_FILE],
pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "",
reverseExt ? version : pkgDataFlags[SO_EXT],
reverseExt ? pkgDataFlags[SO_EXT] : version);
#if defined(__GNUC__) && !defined(__clang__)
_Pragma("GCC diagnostic pop")
#endif

snprintf(cmd, sizeof(cmd), "%s %s %s%s %s%s",
pkgDataFlags[AR],
Expand Down

0 comments on commit 1ff249b

Please sign in to comment.