Use flexible array members.
They are supported by GCC, Clang and MSVC and using them is better than
using arrays of size 1, which actually constitutes undefined behaviour!
Change-Id: I8041d71ffcf7ee6481c000a81a26c0083b726b90
Reviewed-on: https://code-review.googlesource.com/4981
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/re2/dfa.cc b/re2/dfa.cc
index e30aeaf..e33bb01 100644
--- a/re2/dfa.cc
+++ b/re2/dfa.cc
@@ -101,7 +101,7 @@
uint flag_; // Empty string bitfield flags in effect on the way
// into this state, along with kFlagMatch if this
// is a matching state.
- std::atomic<State*> next_[1]; // Outgoing arrows from State,
+ std::atomic<State*> next_[]; // Outgoing arrows from State,
// one per input byte class
};
@@ -469,7 +469,7 @@
// Note that a state stores list heads only, so we use the program
// list count for the upper bound, not the program size.
int nnext = prog_->bytemap_range() + 1; // + 1 for kByteEndText slot
- int64 one_state = sizeof(State) + (nnext-1)*sizeof(std::atomic<State*>) +
+ int64 one_state = sizeof(State) + nnext*sizeof(std::atomic<State*>) +
(prog_->list_count()+nmark)*sizeof(int);
if (state_budget_ < 20*one_state) {
LOG(INFO) << StringPrintf("DFA out of memory: prog size %d mem %lld",
@@ -740,7 +740,7 @@
// State*, empirically.
const int kStateCacheOverhead = 32;
int nnext = prog_->bytemap_range() + 1; // + 1 for kByteEndText slot
- int mem = sizeof(State) + (nnext-1)*sizeof(std::atomic<State*>) +
+ int mem = sizeof(State) + nnext*sizeof(std::atomic<State*>) +
ninst*sizeof(int);
if (mem_budget_ < mem + kStateCacheOverhead) {
mem_budget_ = -1;
diff --git a/re2/onepass.cc b/re2/onepass.cc
index 1d745d4..a6e3321 100644
--- a/re2/onepass.cc
+++ b/re2/onepass.cc
@@ -131,7 +131,7 @@
// the memory footprint.)
struct OneState {
uint32 matchcond; // conditions to match right now.
- uint32 action[1];
+ uint32 action[];
};
// The uint32 conditions in the action are a combination of
@@ -385,7 +385,7 @@
// Limit max node count to 65000 as a conservative estimate to
// avoid overflowing 16-bit node index in encoding.
int maxnodes = 2 + inst_count(kInstByteRange);
- int statesize = sizeof(OneState) + (bytemap_range_-1)*sizeof(uint32);
+ int statesize = sizeof(OneState) + bytemap_range_*sizeof(uint32);
if (maxnodes >= 65000 || dfa_mem_ / 4 / statesize < maxnodes)
return false;