On Thu, Jan 09, 2020 at 01:45:56PM +0100, Michal Privoznik wrote:
In v5.0.0-rc1~94 we switched from one huge switch() to an array
for translating error numbers into error messages. However, the
array is declared to have VIR_ERR_NUMBER_LAST items which makes
it impossible to spot this place by compile checking when adding
new error number.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
scripts/apibuild.py | 6 ++++++
src/util/virerror.c | 4 +++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/scripts/apibuild.py b/scripts/apibuild.py
index 2f7314b379..595c004a4c 100755
--- a/scripts/apibuild.py
+++ b/scripts/apibuild.py
@@ -1657,6 +1657,12 @@ class CParser:
token = ("name", "virloginit")
return token
+ elif token[0] == "name" and token[1] == "G_STATIC_ASSERT":
+ # skip whole line
+ while token is not None and token[0] != "sep" or token[1] !=
";":
This will trigger a TypeError exception if token is None because of operator
precedence.
diff --git a/scripts/apibuild.py b/scripts/apibuild.py
index 595c004a4c..00dd510304 100755
--- a/scripts/apibuild.py
+++ b/scripts/apibuild.py
@@ -1659,7 +1659,8 @@ class CParser:
elif token[0] == "name" and token[1] == "G_STATIC_ASSERT":
# skip whole line
- while token is not None and token[0] != "sep" or token[1] !=
";":
+ while token is not None and (token[0] != "sep" or
+ token[1] != ";"):
token = self.token()
return self.token()
+ token = self.token()
+ return self.token()
+
elif token[0] == "name":
if self.type == "":
self.type = token[1]
diff --git a/src/util/virerror.c b/src/util/virerror.c
index fd2f77329f..aac6ee3597 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -910,7 +910,7 @@ typedef struct {
} virErrorMsgTuple;
-const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NUMBER_LAST] = {
+static const virErrorMsgTuple virErrorMsgStrings[] = {
[VIR_ERR_OK] = { NULL, NULL },
[VIR_ERR_INTERNAL_ERROR] = {
N_("internal error"),
@@ -1235,6 +1235,8 @@ const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NUMBER_LAST] = {
N_("network port not found: %s") },
};
+G_STATIC_ASSERT(G_N_ELEMENTS(virErrorMsgStrings) == VIR_ERR_NUMBER_LAST);
+
Safe for freeze:
Reviewed-by: Erik Skultety <eskultet(a)redhat.com>