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>
// String then StrnLenS returns MaxSize. At most the first MaxSize characters of String shall\r
// be accessed by StrnLenS.\r
//\r
- for (Length = 0; (Length < MaxSize) && (*String != 0); String++, Length++) {\r
- ;\r
+ Length = 0;\r
+ while (String[Length] != 0) {\r
+ if (Length >= MaxSize - 1) {\r
+ return MaxSize;\r
+ }\r
+ Length++;\r
}\r
return Length;\r
}\r
// String then AsciiStrnLenS returns MaxSize. At most the first MaxSize characters of String shall\r
// be accessed by AsciiStrnLenS.\r
//\r
- for (Length = 0; (Length < MaxSize) && (*String != 0); String++, Length++) {\r
- ;\r
+ Length = 0;\r
+ while (String[Length] != 0) {\r
+ if (Length >= MaxSize - 1) {\r
+ return MaxSize;\r
+ }\r
+ Length++;\r
}\r
return Length;\r
}\r