summaryrefslogtreecommitdiffstats
path: root/MdePkg
diff options
context:
space:
mode:
authorHao Wu <hao.a.wu@intel.com>2016-11-15 09:59:37 +0800
committerHao Wu <hao.a.wu@intel.com>2016-12-22 16:17:05 +0800
commitc07c517cc51a4f947022aa5eebe2aace326137e5 (patch)
treec09b964bd31c4ac4a8d19a65a2a1edc012e74586 /MdePkg
parentd0c80b8a2de8ac90f51b86cce24e6c9c267ae5b4 (diff)
downloadedk2-c07c517cc51a4f947022aa5eebe2aace326137e5.tar.gz
edk2-c07c517cc51a4f947022aa5eebe2aace326137e5.tar.bz2
edk2-c07c517cc51a4f947022aa5eebe2aace326137e5.zip
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>
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Library/BaseLib/SafeString.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/MdePkg/Library/BaseLib/SafeString.c b/MdePkg/Library/BaseLib/SafeString.c
index ede2f4c5b4..e4c0759c70 100644
--- a/MdePkg/Library/BaseLib/SafeString.c
+++ b/MdePkg/Library/BaseLib/SafeString.c
@@ -143,8 +143,12 @@ StrnLenS (
// String then StrnLenS returns MaxSize. At most the first MaxSize characters of String shall
// 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;
}
@@ -571,8 +575,12 @@ AsciiStrnLenS (
// String then AsciiStrnLenS returns MaxSize. At most the first MaxSize characters of String shall
// 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;
}