From: guido@trentalancia.com (Guido Trentalancia) Date: Wed, 07 Jun 2017 07:27:25 +0200 Subject: [refpolicy] [PATCH v3] fc_sort: avoid compiler warning/error In-Reply-To: <106e6ea2-192c-1af3-fc08-4738c1aea125@ieee.org> References: <1496674594.4528.3.camel@trentalancia.com> <1496675093.4528.4.camel@trentalancia.com> <1496700493.32176.2.camel@trentalancia.com> <106e6ea2-192c-1af3-fc08-4738c1aea125@ieee.org> Message-ID: <1BEF120D-537D-4FA0-8AA2-8C88C5643637@trentalancia.com> To: refpolicy@oss.tresys.com List-Id: refpolicy.oss.tresys.com Hello. My reply follows the quoted message... On the 7th of June 2017 02:07:49 CEST, Chris PeBenito wrote: >On 06/05/2017 06:08 PM, Guido Trentalancia via refpolicy wrote: >> Fix a "-Werror=implicit-fallthrough" compiler warning/error on >> the switch statement. >> >> This third version (v3) fixes a bug introduced in the first >> version and improves the style over the second version. >> >> Signed-off-by: Guido Trentalancia >> --- >> support/fc_sort.c | 10 ++++++---- >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> --- a/support/fc_sort.c 2017-06-05 23:49:57.280624866 +0200 >> +++ b/support/fc_sort.c 2017-06-06 00:04:48.419621222 +0200 >> @@ -292,14 +292,16 @@ void fc_fill_data(file_context_node_t *f >> /* If a escape character is found, >> * skip the next character. */ >> c++; >> + break; >> default: >> - /* If no meta character has been found yet, >> - * add one to the stem length. */ >> - if (!fc_node->meta) >> - fc_node->stem_len++; >> break; >> } >> >> + /* If no meta character has been found yet, >> + * add one to the stem length. */ >> + if (!fc_node->meta) >> + fc_node->stem_len++; >> + >> fc_node->str_len++; >> c++; >> } > >This doesn't look like a valid change since the block you're doing >shouldn't be done if the current character is a metacharacter. fc_node->stem_len is incremented only if fc_node->meta is zero or, in other words, only if a metacharacter has not been found yet (a condition which does NOT include the case of the current character being a metacharacter). So the "if" block that I simply moved out of the "switch" statement, but inside the "while" loop, is NOT executed if the current character is a metacharacter (because in such case fc_node->meta is one and not zero) ! I hope this helps.... Please consider that, as it is, the fc_sort code does not compile and the Reference Policy is thus unusable. Regards, Guido