Skip to content

Commit

Permalink
Fix sprintf deprecation error with Xcode 14.1 (#77950)
Browse files Browse the repository at this point in the history
* Fix sprintf deprecation error with Xcode 14.1

* Update src/tests/Common/Platform/platformdefines.cpp

Co-authored-by: Aaron Robinson <[email protected]>

Co-authored-by: Aaron Robinson <[email protected]>
  • Loading branch information
AustinWise and AaronRobinsonMSFT authored Nov 8, 2022
1 parent 2aebbf7 commit af841c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/tests/Common/Platform/platformdefines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/tests/nativeaot/SmokeTests/PInvoke/PInvokeNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit af841c8

Please sign in to comment.