Skip to contentSkip to conversation

tests/file_contexts: avoid using a C99-style for loop

PATCH In review Ondrej Mosnacek 2 participants 3 messages Jul 27 – Jul 28 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/file_contexts: avoid using a C99-style for loop

The for loop in assertContextsMatch() seems to be the only code that makes use of C99 features, which means that it fails to build with older compilers, such as GCC on RHEL-7. Avoid this by moving the declaration out of the for loop.

An alternative would be to instead add -std=c99 to CFLAGS, but it seems simpler to just revert to the C90 status quo ante.

---

If someone strongly prefers the -std=c99 solution, feel free to submit an alternative patch. I don't have a strong preference here.

 tests/file_contexts/internal.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/file_contexts/internal.c +3 -1
index 22b5790..20ab428 100644
@@ -13,7 +13,9 @@
 void assertContextsMatch(struct selabel_handle *hnd, struct test_t *tests,
 			 size_t n)
 {
-	for (int i = 0; i < n; i++) {
+	int i;
+
+	for (i = 0; i < n; i++) {
 		char *context = NULL;
 		struct test_t test = tests[i];
 
Signature · 1 line
2.55.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Ondrej Mosnacek

The for loop in assertContextsMatch() seems to be the only code that makes use of C99 features, which means that it fails to build with older compilers, such as GCC on RHEL-7. Avoid this by moving the declaration out of the for loop.

An alternative would be to instead add -std=c99 to CFLAGS, but it seems simpler to just revert to the C90 status quo ante.

It makes me sad that there are still people using RHEL-7 but:

Quoted 27 lines

---

If someone strongly prefers the -std=c99 solution, feel free to submit an alternative patch. I don't have a strong preference here.

 tests/file_contexts/internal.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/file_contexts/internal.c +3 -2
index 22b5790..20ab428 100644
@@ -13,7 +13,9 @@
 void assertContextsMatch(struct selabel_handle *hnd, struct test_t *tests,
                         size_t n)
 {
-       for (int i = 0; i < n; i++) {
+       int i;
+
+       for (i = 0; i < n; i++) {
                char *context = NULL;
                struct test_t test = tests[i];
 
--

2.55.0

maintainer
#2 lore raw
Quoted 8 lines · Stephen Smalley
Quoted 6 lines · Ondrej Mosnacek

The for loop in assertContextsMatch() seems to be the only code that makes use of C99 features, which means that it fails to build with older compilers, such as GCC on RHEL-7. Avoid this by moving the declaration out of the for loop.

Quoted 7 lines
Quoted 4 lines

An alternative would be to instead add -std=c99 to CFLAGS, but it seems simpler to just revert to the C90 status quo ante.

It makes me sad that there are still people using RHEL-7 but:

Thanks, merged.