Skip to content

Commit e6ec2ec

Browse files
committed
MdeModulePkg: Prevent memcpy intrinsics in VS22 (17.14.2)
The latest VS2022 update replaces some code patterns with struct assignments with `memcpy`. This change convert the code to explicitly use `CopyMem`. Signed-off-by: Michael Kubacki <[email protected]>
1 parent 4dc0c19 commit e6ec2ec

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

MdeModulePkg/Universal/DisplayEngineDxe/InputHandler.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,16 @@ ReadString (
229229

230230
case CHAR_BACKSPACE:
231231
if ((StringPtr[0] != CHAR_NULL) && (CurrentCursor != 0)) {
232-
for (Index = 0; Index < CurrentCursor - 1; Index++) {
233-
TempString[Index] = StringPtr[Index];
232+
// MU_CHANGE [BEGIN]: Fix VS22 17.14 memcpy substitution
233+
// for (Index = 0; Index < CurrentCursor - 1; Index++) {
234+
// TempString[Index] = StringPtr[Index];
235+
// }
236+
if (CurrentCursor > 1) {
237+
CopyMem (TempString, StringPtr, (CurrentCursor - 1) * sizeof (CHAR16));
234238
}
235239

240+
// MU_CHANGE [END]: Fix VS22 17.14 memcpy substitution
241+
236242
Count = GetStringWidth (StringPtr) / 2 - 1;
237243
if (Count >= CurrentCursor) {
238244
for (Index = CurrentCursor - 1, Index2 = CurrentCursor; Index2 < Count; Index++, Index2++) {
@@ -261,9 +267,12 @@ ReadString (
261267
KeyPad[1] = CHAR_NULL;
262268
Count = GetStringWidth (StringPtr) / 2 - 1;
263269
if (CurrentCursor < Count) {
264-
for (Index = 0; Index < CurrentCursor; Index++) {
265-
TempString[Index] = StringPtr[Index];
266-
}
270+
// MU_CHANGE [BEGIN]: Fix VS22 17.14 memcpy substitution
271+
// for (Index = 0; Index < CurrentCursor; Index++) {
272+
// TempString[Index] = StringPtr[Index];
273+
// }
274+
CopyMem (TempString, StringPtr, CurrentCursor * sizeof (CHAR16));
275+
// MU_CHANGE [END]: Fix VS22 17.14 memcpy substitution
267276

268277
TempString[Index] = CHAR_NULL;
269278
StrCatS (TempString, MaxLen, KeyPad);

ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ HBufferImageBackup (
143143
)
144144
{
145145
// MU_CHANGE [BEGIN]: Fix VS22 17.14 memcpy substitution
146-
HBufferImageBackupVar.MousePosition = HBufferImage.MousePosition;
146+
// HBufferImageBackupVar.MousePosition = HBufferImage.MousePosition;
147147

148-
HBufferImageBackupVar.BufferPosition = HBufferImage.BufferPosition;
148+
// HBufferImageBackupVar.BufferPosition = HBufferImage.BufferPosition;
149149
CopyMem (&HBufferImageBackupVar.MousePosition, &HBufferImage.MousePosition, sizeof (HBufferImage.MousePosition));
150150
CopyMem (&HBufferImageBackupVar.BufferPosition, &HBufferImage.BufferPosition, sizeof (HBufferImage.BufferPosition));
151151
// MU_CHANGE [END]: Fix VS22 17.14 memcpy substitution

0 commit comments

Comments
 (0)