https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f5ba9de2ee1ab825d9dd1…
commit f5ba9de2ee1ab825d9dd108fade57860db0fad79
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Mon Sep 28 00:30:18 2020 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Mon Sep 28 00:41:17 2020 +0200
[CMD] Fix substring-substitute regression from commit cdc8e45b (use signed offsets).
---
base/shell/cmd/cmd.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c
index a3253026f10..e92426d8cb3 100644
--- a/base/shell/cmd/cmd.c
+++ b/base/shell/cmd/cmd.c
@@ -1421,21 +1421,19 @@ do { \
}
else if (*Src == _T('~'))
{
- /* %VAR:~[start][,length]% - substring
+ /* %VAR:~[start][,length]% - Substring.
* Negative values are offsets from the end.
*/
- size_t Start = _tcstol(Src + 1, (PTSTR*)&Src, 0);
- size_t End = VarLength;
+ SSIZE_T Start = _tcstol(Src + 1, (PTSTR*)&Src, 0);
+ SSIZE_T End = (SSIZE_T)VarLength;
if (Start < 0)
Start += VarLength;
- Start = max(Start, 0);
- Start = min(Start, VarLength);
+ Start = min(max(Start, 0), VarLength);
if (*Src == _T(','))
{
End = _tcstol(Src + 1, (PTSTR*)&Src, 0);
End += (End < 0) ? VarLength : Start;
- End = max(End, Start);
- End = min(End, VarLength);
+ End = min(max(End, Start), VarLength);
}
if (*Src++ != Delim)
goto bad_subst;