Skip to content

Commit

Permalink
amend to #222: prevent merge errors by unexpected growing of properti…
Browse files Browse the repository at this point in the history
…es enum in compilers supporting constexpr/static_assert, checking its length at compile time:

ARRAY_SIZE(g_NameToPropID) must be always equal NCoderPropID::kEndOfProp
  • Loading branch information
sebres committed Aug 26, 2021
1 parent df06f31 commit f5dc5b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CPP/7zip/Common/MethodProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ static const CNameToPropID g_NameToPropID[] =
{ VT_UI4, "ldmhevery" }
};

#if defined(static_assert) || (__STDC_VERSION >= 201112L) || (_MSC_VER >= 1900)
static_assert(ARRAY_SIZE(g_NameToPropID) == NCoderPropID::kEndOfProp,
"g_NameToPropID doesn't match NCoderPropID enum");
#endif

static int FindPropIdExact(const UString &name)
{
for (unsigned i = 0; i < ARRAY_SIZE(g_NameToPropID); i++)
Expand Down
3 changes: 2 additions & 1 deletion CPP/7zip/ICoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ namespace NCoderPropID
kLdmHashLog, // VT_UI4 The minimum ldmhlog is 6 and the maximum is 26 (default: 20).
kLdmSearchLength, // VT_UI4 The minimum ldmslen is 4 and the maximum is 4096 (default: 64).
kLdmBucketSizeLog, // VT_UI4 The minimum ldmblog is 0 and the maximum is 8 (default: 3).
kLdmHashRateLog // VT_UI4 The default value is wlog - ldmhlog.
kLdmHashRateLog, // VT_UI4 The default value is wlog - ldmhlog.
kEndOfProp
};
}

Expand Down

0 comments on commit f5dc5b2

Please sign in to comment.