/** @file\r
Safe String functions.\r
\r
- Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
//\r
// 4. If Length is not less than DestMax, then DestMax shall be greater than StrnLenS(Source, DestMax).\r
//\r
- SourceLen = StrnLenS (Source, DestMax);\r
+ SourceLen = StrnLenS (Source, MIN (DestMax, Length));\r
if (Length >= DestMax) {\r
SAFE_STRING_CONSTRAINT_CHECK ((DestMax > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
}\r
// pointed to by Destination. If no null character was copied from Source, then Destination[Length] is set to a null\r
// character.\r
//\r
- while ((*Source != 0) && (SourceLen > 0)) {\r
+ while ((SourceLen > 0) && (*Source != 0)) {\r
*(Destination++) = *(Source++);\r
SourceLen--;\r
}\r
//\r
// 5. If Length is not less than CopyLen, then CopyLen shall be greater than StrnLenS(Source, CopyLen).\r
//\r
- SourceLen = StrnLenS (Source, CopyLen);\r
+ SourceLen = StrnLenS (Source, MIN (CopyLen, Length));\r
if (Length >= CopyLen) {\r
SAFE_STRING_CONSTRAINT_CHECK ((CopyLen > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
}\r
// a null character.\r
//\r
Destination = Destination + DestLen;\r
- while ((*Source != 0) && (SourceLen > 0)) {\r
+ while ((SourceLen > 0) && (*Source != 0)) {\r
*(Destination++) = *(Source++);\r
SourceLen--;\r
}\r
//\r
// 4. If Length is not less than DestMax, then DestMax shall be greater than AsciiStrnLenS(Source, DestMax).\r
//\r
- SourceLen = AsciiStrnLenS (Source, DestMax);\r
+ SourceLen = AsciiStrnLenS (Source, MIN (DestMax, Length));\r
if (Length >= DestMax) {\r
SAFE_STRING_CONSTRAINT_CHECK ((DestMax > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
}\r
// pointed to by Destination. If no null character was copied from Source, then Destination[Length] is set to a null\r
// character.\r
//\r
- while ((*Source != 0) && (SourceLen > 0)) {\r
+ while ((SourceLen > 0) && (*Source != 0)) {\r
*(Destination++) = *(Source++);\r
SourceLen--;\r
}\r
//\r
// 5. If Length is not less than CopyLen, then CopyLen shall be greater than AsciiStrnLenS(Source, CopyLen).\r
//\r
- SourceLen = AsciiStrnLenS (Source, CopyLen);\r
+ SourceLen = AsciiStrnLenS (Source, MIN (CopyLen, Length));\r
if (Length >= CopyLen) {\r
SAFE_STRING_CONSTRAINT_CHECK ((CopyLen > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
}\r
// a null character.\r
//\r
Destination = Destination + DestLen;\r
- while ((*Source != 0) && (SourceLen > 0)) {\r
+ while ((SourceLen > 0) && (*Source != 0)) {\r
*(Destination++) = *(Source++);\r
SourceLen--;\r
}\r