Skip to contentSkip to conversation

libs/igt_core.c: Fix compile warnings in igt_core.c

PATCH Superseded Derek Morton 2 participants 2 messages May 19, 2015 – May 20, 2015 Library code

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libs/igt_core.c: Fix compile warnings in igt_core.c

Fixed variables incorrectly declared as signed instead of unsigned.

Fixed 'unused parameter' warning from signal handlers that were not using the signal parameter.

v2: Addressed comments from Tim Gore

---
 lib/igt_core.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
lib/igt_core.c +13 -7
index 8a1a249..62b1e6a 100644
@@ -1104,7 +1104,7 @@ static pid_t helper_process_pids[] =
 
 static void reset_helper_process_list(void)
 {
-	for (int i = 0; i < ARRAY_SIZE(helper_process_pids); i++)
+	for (unsigned int i = 0; i < ARRAY_SIZE(helper_process_pids); i++)
 		helper_process_pids[i] = -1;
 	helper_process_count = 0;
 }
@@ -1121,8 +1121,10 @@ static int __waitpid(pid_t pid)
 
 static void fork_helper_exit_handler(int sig)
 {
+	(void)sig; /* Not used, suppress warning */
+
 	/* Inside a signal handler, play safe */
-	for (int i = 0; i < ARRAY_SIZE(helper_process_pids); i++) {
+	for (unsigned int i = 0; i < ARRAY_SIZE(helper_process_pids); i++) {
 		pid_t pid = helper_process_pids[i];
 		if (pid != -1) {
 			kill(pid, SIGTERM);
@@ -1227,6 +1229,8 @@ static void children_exit_handler(int sig)
 {
 	int status;
 
+	(void)sig; /* Not used, suppress warning */
+
 	/* The exit handler can be called from a fatal signal, so play safe */
 	while (num_test_children-- && wait(&status))
 		;
@@ -1376,10 +1380,10 @@ static void restore_sig_handler(int sig_num)
 
 static void restore_all_sig_handler(void)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(orig_sig); i++)
-		restore_sig_handler(i);
+		restore_sig_handler((int)i);
 }
 
 static void call_exit_handlers(int sig)
@@ -1419,7 +1423,7 @@ static bool crash_signal(int sig)
 
 static void fatal_sig_handler(int sig)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(handled_signals); i++) {
 		if (handled_signals[i].number != sig)
@@ -1481,7 +1485,7 @@ static void fatal_sig_handler(int sig)
  */
 void igt_install_exit_handler(igt_exit_handler_t fn)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < exit_handler_count; i++)
 		if (exit_handler_fn[i] == fn)
@@ -1521,7 +1525,7 @@ err:
 void igt_disable_exit_handler(void)
 {
 	sigset_t set;
-	int i;
+	unsigned int i;
 
 	if (exit_handler_disabled)
 		return;
@@ -1724,6 +1728,8 @@ out:
 
 static void igt_alarm_handler(int signal)
 {
+	(void)signal; /* Not used, suppress warning */
+
 	igt_info("Timed out\n");
 
 	/* exit with failure status */
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 26 lines · Derek Morton

Fixed variables incorrectly declared as signed instead of unsigned.

Fixed 'unused parameter' warning from signal handlers that were not using the signal parameter.

v2: Addressed comments from Tim Gore

---
 lib/igt_core.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
lib/igt_core.c +1 -1
index 8a1a249..62b1e6a 100644
@@ -1104,7 +1104,7 @@ static pid_t helper_process_pids[] =
 
 static void reset_helper_process_list(void)
 {
-	for (int i = 0; i < ARRAY_SIZE(helper_process_pids); i++)
+	for (unsigned int i = 0; i < ARRAY_SIZE(helper_process_pids); i++)
 		helper_process_pids[i] = -1;
 	helper_process_count = 0;
 }

lib/igt_core.c static int __waitpid(pid_t pid) · line 1124

Quoted 4 lines
lib/igt_core.c +1 -0
@@ -1121,8 +1121,10 @@ static int __waitpid(pid_t pid)
 
 static void fork_helper_exit_handler(int sig)
 {
+	(void)sig; /* Not used, suppress warning */

No, this is not the way to go.

If you really want to get rid of the warning (not enabled by default), you should define a macro:

#define unused(x) x __attribute__ ((unused))

and make the change:

-static void fork_helper_exit_handler(int sig) +static void fork_helper_exit_handler(unused(int sig))

And to make that right, you should define unused depending on the compiler you're using.

Quoted 17 lines
lib/igt_core.c +4 -1
+
 	/* Inside a signal handler, play safe */
-	for (int i = 0; i < ARRAY_SIZE(helper_process_pids); i++) {
+	for (unsigned int i = 0; i < ARRAY_SIZE(helper_process_pids); i++) {
 		pid_t pid = helper_process_pids[i];
 		if (pid != -1) {
 			kill(pid, SIGTERM);
@@ -1227,6 +1229,8 @@ static void children_exit_handler(int sig)
 {
 	int status;
 
+	(void)sig; /* Not used, suppress warning */
+
 	/* The exit handler can be called from a fatal signal, so play safe */
 	while (num_test_children-- && wait(&status))
 		;

lib/igt_core.c static void restore_sig_handler(int sig_num) · line 1386

Quoted 9 lines
lib/igt_core.c +2 -2
@@ -1376,10 +1380,10 @@ static void restore_sig_handler(int sig_num)
 
 static void restore_all_sig_handler(void)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(orig_sig); i++)
-		restore_sig_handler(i);
+		restore_sig_handler((int)i);

I think the warning is much better than having an explicit cast in the code like this.

BR,
Jani.

Quoted 46 lines
lib/igt_core.c +5 -3
 }
 
 static void call_exit_handlers(int sig)
@@ -1419,7 +1423,7 @@ static bool crash_signal(int sig)
 
 static void fatal_sig_handler(int sig)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(handled_signals); i++) {
 		if (handled_signals[i].number != sig)
@@ -1481,7 +1485,7 @@ static void fatal_sig_handler(int sig)
  */
 void igt_install_exit_handler(igt_exit_handler_t fn)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < exit_handler_count; i++)
 		if (exit_handler_fn[i] == fn)
@@ -1521,7 +1525,7 @@ err:
 void igt_disable_exit_handler(void)
 {
 	sigset_t set;
-	int i;
+	unsigned int i;
 
 	if (exit_handler_disabled)
 		return;
@@ -1724,6 +1728,8 @@ out:
 
 static void igt_alarm_handler(int signal)
 {
+	(void)signal; /* Not used, suppress warning */
+
 	igt_info("Timed out\n");
 
 	/* exit with failure status */
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx