\r
ASSERT (DevicePath != NULL);\r
\r
- if (MaxSize == 0){\r
- MaxSize = MAX_UINTN;\r
- }\r
-\r
- Size = 0;\r
- Count = 0;\r
-\r
- while (MaxSize >= sizeof (EFI_DEVICE_PATH_PROTOCOL) &&\r
- (MaxSize - sizeof (EFI_DEVICE_PATH_PROTOCOL) >= Size) &&\r
- !IsDevicePathEnd (DevicePath)) {\r
+ for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r
NodeLength = DevicePathNodeLength (DevicePath);\r
if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
return FALSE;\r
}\r
\r
- if (NodeLength > MAX_UINTN - Size) {\r
- return FALSE;\r
+ if (MaxSize > 0) {\r
+ Size += NodeLength;\r
+ if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {\r
+ return FALSE;\r
+ }\r
}\r
\r
- Size += NodeLength;\r
-\r
if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {\r
Count++;\r
if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {\r
return FALSE;\r
}\r
}\r
-\r
- DevicePath = NextDevicePathNode (DevicePath);\r
}\r
\r
//\r