[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/10] glr2.cc: fix memory corruption bug
From: |
Akim Demaille |
Subject: |
[PATCH 05/10] glr2.cc: fix memory corruption bug |
Date: |
Sun, 6 Dec 2020 14:10:32 +0100 |
From: Valentin Tolmer <valentin.tolmer@gmail.com>
* data/skeletons/glr2.cc (yyremoveDeletes): Remove double-increment in
the loop.
(glr_state::copyFrom): Handle gracefully when other is resolved.
---
data/skeletons/glr2.cc | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 748d51de..f334478e 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -799,7 +799,11 @@ public:
void copyFrom(const glr_state& other) {
*this = other;
setPred(other.pred());
- setFirstVal(other.firstVal());
+ if (other.yyresolved) {
+ semanticVal() = other.semanticVal();
+ } else {
+ setFirstVal(other.firstVal());
+ }
}
/** Type tag for If true, yysval applies, otherwise
@@ -945,9 +949,9 @@ class glr_state_set {
inline void
yyremoveDeletes ()
{
- std::ptrdiff_t newsize = static_cast<std::ptrdiff_t>(yystates.size());
+ size_t newsize = yystates.size();
/* j is the number of live stacks we have seen. */
- for (size_t i = 0, j = 0; i < yystates.size(); ++i)
+ for (size_t i = 0, j = 0; j < newsize; ++i)
{
if (yystates[i] == YY_NULLPTR)
{
@@ -972,10 +976,9 @@ class glr_state_set {
}
j += 1;
}
- i += 1;
}
- yystates.erase(yystates.begin() + newsize, yystates.end());
- yylookaheadNeeds.erase(yylookaheadNeeds.begin() + newsize,
+ yystates.erase(yystates.begin() + static_cast<std::ptrdiff_t>(newsize),
yystates.end());
+ yylookaheadNeeds.erase(yylookaheadNeeds.begin() +
static_cast<std::ptrdiff_t>(newsize),
yylookaheadNeeds.end());
}
--
2.29.2
- [PATCH 00/10] glr2.cc: fixes, Akim Demaille, 2020/12/06
- [PATCH 01/10] glr.c: fix line numbers in logs, Akim Demaille, 2020/12/06
- [PATCH 02/10] glr2.cc: fix when the stack is not expandable, Akim Demaille, 2020/12/06
- [PATCH 03/10] glr2.cc: use 'const' for some constant local variables, Akim Demaille, 2020/12/06
- [PATCH 04/10] glr2.cc: turn some pointers into references, Akim Demaille, 2020/12/06
- [PATCH 05/10] glr2.cc: fix memory corruption bug,
Akim Demaille <=
- [PATCH 06/10] glr2.cc: misc cleanups, Akim Demaille, 2020/12/06
- [PATCH 07/10] glr2.cc: fix yyresolveValue, Akim Demaille, 2020/12/06
- [PATCH 08/10] glr2.cc: add support for parse.assert, Akim Demaille, 2020/12/06
- [PATCH 09/10] glr2.cc: use the same format for traces as glr.c, Akim Demaille, 2020/12/06
- [PATCH 10/10] glr2.cc: run the glr-regression tests, Akim Demaille, 2020/12/06