From 07d5ea89b83e0176f7e51bd8b0ae9881aadff3bf Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Thu, 19 Nov 2015 14:17:36 +0000 Subject: [PATCH 3/3] pyhbac: Fix warning Wsign-compare MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit src/python/pyhbac.c: In function ‘HbacRuleElement_repr’: src/python/pyhbac.c:506:59: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] if (strnames == NULL || strgroups == NULL || category == -1) { ^ src/python/pyhbac.c: In function ‘HbacRuleElement_to_native’: src/python/pyhbac.c:614:51: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] if (!el->names || !el->groups || el->category == -1) { ^ The static function native_category had type of terurn value uint32_t But it also could return -1 which indicated an error. It's better to don't mix return code with returned value. --- src/python/pyhbac.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/python/pyhbac.c b/src/python/pyhbac.c index fca476c56ba697693c793ecad7945ae7edf3dffd..820ef11b57f1226725fd7acf97598a42e6bf0bc0 100644 --- a/src/python/pyhbac.c +++ b/src/python/pyhbac.c @@ -191,8 +191,8 @@ pyobject_to_category(PyObject *o) return -1; } -static uint32_t -native_category(PyObject *pycat) +static int +native_category(PyObject *pycat, uint32_t *_category) { PyObject *iterator; PyObject *item; @@ -218,7 +218,9 @@ native_category(PyObject *pycat) } Py_DECREF(iterator); - return cat; + + *_category = cat; + return 0; } static char * @@ -491,6 +493,7 @@ HbacRuleElement_repr(HbacRuleElement *self) char *strnames = NULL; char *strgroups = NULL; uint32_t category; + int ret; PyObject *o, *format, *args; format = PyUnicode_FromString(""); @@ -502,8 +505,8 @@ HbacRuleElement_repr(HbacRuleElement *self) discard_const_p(char, ",")); strgroups = str_concat_sequence(self->groups, discard_const_p(char, ",")); - category = native_category(self->category); - if (strnames == NULL || strgroups == NULL || category == -1) { + ret = native_category(self->category, &category); + if (strnames == NULL || strgroups == NULL || ret == -1) { PyMem_Free(strnames); PyMem_Free(strgroups); Py_DECREF(format); @@ -592,6 +595,7 @@ struct hbac_rule_element * HbacRuleElement_to_native(HbacRuleElement *pyel) { struct hbac_rule_element *el = NULL; + int ret; /* check the type, None would wreak havoc here because for some reason * it would pass the sequence check */ @@ -608,10 +612,10 @@ HbacRuleElement_to_native(HbacRuleElement *pyel) goto fail; } - el->category = native_category(pyel->category); + ret = native_category(pyel->category, &el->category); el->names = sequence_as_string_list(pyel->names, "names"); el->groups = sequence_as_string_list(pyel->groups, "groups"); - if (!el->names || !el->groups || el->category == -1) { + if (!el->names || !el->groups || ret == -1) { goto fail; } -- 2.5.0