From af841c8b33cecc92d74222298f1e45bf7bf3d90a Mon Sep 17 00:00:00 2001 From: Austin Wise Date: Mon, 7 Nov 2022 21:47:52 -0800 Subject: [PATCH] Fix sprintf deprecation error with Xcode 14.1 (#77950) * Fix sprintf deprecation error with Xcode 14.1 * Update src/tests/Common/Platform/platformdefines.cpp Co-authored-by: Aaron Robinson Co-authored-by: Aaron Robinson --- src/tests/Common/Platform/platformdefines.cpp | 5 +++-- src/tests/nativeaot/SmokeTests/PInvoke/PInvokeNative.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tests/Common/Platform/platformdefines.cpp b/src/tests/Common/Platform/platformdefines.cpp index 5f42534d10a82..1a31cfae414bd 100644 --- a/src/tests/Common/Platform/platformdefines.cpp +++ b/src/tests/Common/Platform/platformdefines.cpp @@ -170,8 +170,9 @@ error_t TP_putenv_s(LPWSTR name, LPWSTR value) return 0; #else int retVal = 0; - char *assignment = (char*) malloc(sizeof(char) * (TP_slen(name) + TP_slen(value) + 1)); - sprintf(assignment, "%s=%s", HackyConvertToSTR(name), HackyConvertToSTR(value)); + size_t assignmentSize = sizeof(char) * (TP_slen(name) + TP_slen(value) + 1 + 1); + char *assignment = (char*) malloc(assignmentSize); + snprintf(assignment, assignmentSize, "%s=%s", HackyConvertToSTR(name), HackyConvertToSTR(value)); if (0 != putenv(assignment)) retVal = 2; diff --git a/src/tests/nativeaot/SmokeTests/PInvoke/PInvokeNative.cpp b/src/tests/nativeaot/SmokeTests/PInvoke/PInvokeNative.cpp index 480209d3b2560..43f9db11df1b6 100644 --- a/src/tests/nativeaot/SmokeTests/PInvoke/PInvokeNative.cpp +++ b/src/tests/nativeaot/SmokeTests/PInvoke/PInvokeNative.cpp @@ -569,12 +569,12 @@ DLL_EXPORT bool __stdcall StructTest_Array(NativeSequentialStruct *nss, int leng return false; if (nss[i].b != i*i) return false; - sprintf(expected, "%d", i); + snprintf(expected, sizeof(expected), "%d", i); if (CompareAnsiString(expected, nss[i].str) == 0) return false; - sprintf(expected, "u8%d", i); + snprintf(expected, sizeof(expected), "u8%d", i); if (CompareAnsiString(expected, nss[i].u8str) == 0) return false;