Skip to contentSkip to conversation

fc_sort: avoid compiler warning/error

PATCH Superseded Guido Trentalancia 4 participants 9 messages Jun 5, 2017 – Jun 7, 2017

lore
Share & tools
lore
#2 lore raw

PATCH v2 1/1 fc_sort: avoid compiler warning/error

In reply to Guido Trentalancia

Or maybe just add a comment /*FALLTHRU*/ ?
This should silence the warning.

https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/

Quoted 25 lines · Guido Trentalancia via refpolicy

Fix a "-Werror=implicit-fallthrough" compiler warning/error on the switch statement.

This second version (v2) fixes a bug introduced with the previous version.

---
 support/fc_sort.c |    5 +++++
 1 file changed, 5 insertions(+)
support/fc_sort.c 2017-06-05 17:01:44.818724998 +0200 renamed from support/fc_sort.c 2017-03-29 17:57:54.576386420 +0200 +5 -0
@@ -292,6 +292,11 @@ void fc_fill_data(file_context_node_t *f
                        /* If a escape character is found,
                         *  skip the next character. */
                        c++;
+                       /* If no meta character has been found yet,
+                        * add one to the stem length. */
+                       if (!fc_node->meta)
+                               fc_node->stem_len++;
+                       break;
                default:
                        /* If no meta character has been found yet,
                         *  add one to the stem length. */
Quoted 5 lines

_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.tresys.com/pipermail/refpolicy/attachments/20170605/f8516853/attachment-0001.html

#0 lore raw

PATCH 1/1 fc_sort: avoid compiler warning/error

Fix a "-Werror=implicit-fallthrough" compiler warning/error on the switch statement.

---
 support/fc_sort.c |    1 +
 1 file changed, 1 insertion(+)
support/fc_sort.c +1 -0
@@ -292,6 +292,7 @@ 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. */
#1 lore raw

PATCH v2 1/1 fc_sort: avoid compiler warning/error

Fix a "-Werror=implicit-fallthrough" compiler warning/error on the switch statement.

This second version (v2) fixes a bug introduced with the previous version.

---
 support/fc_sort.c |    5 +++++
 1 file changed, 5 insertions(+)
support/fc_sort.c +5 -0
@@ -292,6 +292,11 @@ void fc_fill_data(file_context_node_t *f
 			/* If a escape character is found,
 			 *  skip the next character. */
 			c++;
+			/* If no meta character has been found yet,
+			 * add one to the stem length. */
+			if (!fc_node->meta)
+				fc_node->stem_len++;
+			break;
 		default:
 			/* If no meta character has been found yet,
 			 *  add one to the stem length. */
#3 lore raw

PATCH v2 1/1 fc_sort: avoid compiler warning/error

In reply to Christian Göttsche

Hello,

thanks for telling me about this option, but I prefer to leave things as they are, without being too much specific to the particular compiler.

Regards,

Guido

Quoted 38 lines · Christian G?ttsche

Or maybe just add a comment /*FALLTHRU*/ ?
This should silence the warning.

https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/

Quoted 30 lines · Guido Trentalancia via refpolicy

Fix a "-Werror=implicit-fallthrough" compiler warning/error on the switch statement.

This second version (v2) fixes a bug introduced with the previous version.

---
 support/fc_sort.c |    5 +++++
 1 file changed, 5 insertions(+)
support/fc_sort.c 2017-06-05 17:01:44.818724998 +0200 renamed from support/fc_sort.c 2017-03-29 17:57:54.576386420 +0200 +5 -0
@@ -292,6 +292,11 @@ void fc_fill_data(file_context_node_t *f
                        /* If a escape character is found,
                         *  skip the next character. */
                        c++;
+                       /* If no meta character has been found yet,
+                        * add one to the stem length. */
+                       if (!fc_node->meta)
+                               fc_node->stem_len++;
+                       break;
                default:
                        /* If no meta character has been found yet,
                         *  add one to the stem length. */

_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy

#4 lore raw

PATCH v2 1/1 fc_sort: avoid compiler warning/error

In reply to Guido Trentalancia
Quoted 14 lines · Guido Trentalancia via refpolicy

Fix a "-Werror=implicit-fallthrough" compiler warning/error on the switch statement.

This second version (v2) fixes a bug introduced with the previous version.

---
 support/fc_sort.c |    5 +++++
 1 file changed, 5 insertions(+)

support/fc_sort.c void fc_fill_data(file_context_node_t *f · line 299

Quoted 8 lines
support/fc_sort.c +5 -0
@@ -292,6 +292,11 @@ void fc_fill_data(file_context_node_t *f
 			/* If a escape character is found,
 			 *  skip the next character. */
 			c++;
+			/* If no meta character has been found yet,
+			 * add one to the stem length. */
+			if (!fc_node->meta)
+				fc_node->stem_len++;
+			break;

Why not just add /* -fallthrough */ instead of the break?

Seems more maintainable than duplicating the code in case something changes later.

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

-- Jason

Quoted 7 lines
support/fc_sort.c +0 -0
 		default:
 			/* If no meta character has been found yet,
 			 *  add one to the stem length. */

_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy

#5 lore raw

PATCH v3 1/1 fc_sort: avoid compiler warning/error

In reply to Guido Trentalancia

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.

---
 support/fc_sort.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
support/fc_sort.c +6 -4
@@ -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++;
 	}
#6 lore raw

PATCH v3 1/1 fc_sort: avoid compiler warning/error

Quoted 24 lines · Guido Trentalancia via refpolicy

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.

---
 support/fc_sort.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
support/fc_sort.c +1 -4
@@ -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;

support/fc_sort.c void fc_fill_data(file_context_node_t *f · line 307

Quoted 10 lines
support/fc_sort.c +5 -0
 		}
 
+		/* 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.

Signature · 1 line
Chris PeBenito
#7 lore raw

PATCH v3 1/1 fc_sort: avoid compiler warning/error

Hello.

My reply follows the quoted message...

Quoted 27 lines · Chris PeBenito
Quoted 26 lines · Guido Trentalancia via refpolicy

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.

---
 support/fc_sort.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
support/fc_sort.c +1 -4
@@ -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;
 		}
 
Quoted 11 lines

support/fc_sort.c void fc_fill_data(file_context_node_t *f · line 307

Quoted 8 lines
support/fc_sort.c +5 -0
+		/* 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

#8 lore raw

PATCH v3 1/1 fc_sort: avoid compiler warning/error

In reply to Guido Trentalancia
Quoted 24 lines · Guido Trentalancia via refpolicy

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.

---
 support/fc_sort.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
support/fc_sort.c +1 -4
@@ -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;

support/fc_sort.c void fc_fill_data(file_context_node_t *f · line 307

Quoted 10 lines
support/fc_sort.c +5 -0
 		}
 
+		/* 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++;
 	}

Merged.

Signature · 1 line
Chris PeBenito