MdePkg/BaseLib: Refine (Ascii)StrnLenS functions logic
This commit refines the logic for AsciiStrnLenS and StrnLenS. It makes the logic more straightforward to prevent possible mis-reports by static code checkers. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
d0c80b8a2d
commit
c07c517cc5
@ -143,8 +143,12 @@ StrnLenS (
|
|||||||
// String then StrnLenS returns MaxSize. At most the first MaxSize characters of String shall
|
// String then StrnLenS returns MaxSize. At most the first MaxSize characters of String shall
|
||||||
// be accessed by StrnLenS.
|
// be accessed by StrnLenS.
|
||||||
//
|
//
|
||||||
for (Length = 0; (Length < MaxSize) && (*String != 0); String++, Length++) {
|
Length = 0;
|
||||||
;
|
while (String[Length] != 0) {
|
||||||
|
if (Length >= MaxSize - 1) {
|
||||||
|
return MaxSize;
|
||||||
|
}
|
||||||
|
Length++;
|
||||||
}
|
}
|
||||||
return Length;
|
return Length;
|
||||||
}
|
}
|
||||||
@ -571,8 +575,12 @@ AsciiStrnLenS (
|
|||||||
// String then AsciiStrnLenS returns MaxSize. At most the first MaxSize characters of String shall
|
// String then AsciiStrnLenS returns MaxSize. At most the first MaxSize characters of String shall
|
||||||
// be accessed by AsciiStrnLenS.
|
// be accessed by AsciiStrnLenS.
|
||||||
//
|
//
|
||||||
for (Length = 0; (Length < MaxSize) && (*String != 0); String++, Length++) {
|
Length = 0;
|
||||||
;
|
while (String[Length] != 0) {
|
||||||
|
if (Length >= MaxSize - 1) {
|
||||||
|
return MaxSize;
|
||||||
|
}
|
||||||
|
Length++;
|
||||||
}
|
}
|
||||||
return Length;
|
return Length;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user