diff mbox series

[2/3] syscalls/pipe*: Fix compiler warnings

Message ID 1519977744-1595-2-git-send-email-huangjh.jy@cn.fujitsu.com
State Accepted
Delegated to: Petr Vorel
Headers show
Series [1/3] syscalls/fchmod*: Fix compiler warnings | expand

Commit Message

Jinhui Huang March 2, 2018, 8:02 a.m. UTC
Signed-off-by: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/pipe/pipe04.c | 2 +-
 testcases/kernel/syscalls/pipe/pipe05.c | 4 ++--
 testcases/kernel/syscalls/pipe/pipe07.c | 2 +-
 testcases/kernel/syscalls/pipe/pipe08.c | 2 ++
 testcases/kernel/syscalls/pipe/pipe11.c | 6 +++---
 5 files changed, 9 insertions(+), 7 deletions(-)

Comments

Petr Vorel March 5, 2018, 8:03 a.m. UTC | #1
Hi Jinhui,

> Signed-off-by: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
> ---
>  testcases/kernel/syscalls/pipe/pipe04.c | 2 +-
>  testcases/kernel/syscalls/pipe/pipe05.c | 4 ++--
>  testcases/kernel/syscalls/pipe/pipe07.c | 2 +-
>  testcases/kernel/syscalls/pipe/pipe08.c | 2 ++
>  testcases/kernel/syscalls/pipe/pipe11.c | 6 +++---
>  5 files changed, 9 insertions(+), 7 deletions(-)

> diff --git a/testcases/kernel/syscalls/pipe/pipe04.c b/testcases/kernel/syscalls/pipe/pipe04.c
> index b3d255b..a3c56e3 100644
> --- a/testcases/kernel/syscalls/pipe/pipe04.c
> +++ b/testcases/kernel/syscalls/pipe/pipe04.c
> @@ -235,7 +235,7 @@ void c2func(void)
>  			tst_resm(TBROK | TERRNO, "[child 2] pipe write failed");
>  }

> -void alarmfunc(int sig)
> +void alarmfunc(int sig LTP_ATTRIBUTE_UNUSED)
>  {
>  	/* for some reason tst_brkm doesn't seem to work in a signal handler */
>  	tst_brkm(TFAIL, cleanup, "one or more children did't die in 60 second "
> diff --git a/testcases/kernel/syscalls/pipe/pipe05.c b/testcases/kernel/syscalls/pipe/pipe05.c
> index fe5ec37..4105988 100644
> --- a/testcases/kernel/syscalls/pipe/pipe05.c
> +++ b/testcases/kernel/syscalls/pipe/pipe05.c
> @@ -59,7 +59,7 @@ void sig11_handler(int sig);

>  int main(int ac, char **av)
>  {
> -	int lc;
> +	volatile int lc;
Why volatile?

>  	struct sigaction sa, osa;

>  	tst_parse_opts(ac, av, NULL, NULL);
> @@ -120,7 +120,7 @@ void setup(void)
>  /******************************************************************
>   * sig11_handler() - our segfault recover hack
>   ******************************************************************/
> -void sig11_handler(int sig)
> +void sig11_handler(int sig LTP_ATTRIBUTE_UNUSED)
>  {
>  	longjmp(sig11_recover, 1);
>  }
> diff --git a/testcases/kernel/syscalls/pipe/pipe07.c b/testcases/kernel/syscalls/pipe/pipe07.c
> index b09df71..55bb9f4 100644
> --- a/testcases/kernel/syscalls/pipe/pipe07.c
> +++ b/testcases/kernel/syscalls/pipe/pipe07.c
> @@ -129,7 +129,7 @@ static void record_open_fds(void)
>  		if (fd == dir_fd)
>  			continue;

> -		if (rec_fds_max >= ARRAY_SIZE(rec_fds)) {
> +		if (rec_fds_max >= (int)ARRAY_SIZE(rec_fds)) {
>  			tst_brkm(TBROK, cleanup,
>  			         "Too much file descriptors open");
>  		}
> diff --git a/testcases/kernel/syscalls/pipe/pipe08.c b/testcases/kernel/syscalls/pipe/pipe08.c
> index cdb2a4d..9f8d9cc 100644
> --- a/testcases/kernel/syscalls/pipe/pipe08.c
> +++ b/testcases/kernel/syscalls/pipe/pipe08.c
> @@ -98,6 +98,8 @@ int main(int ac, char **av)
>  		 * sent
>  		 */
>  		written = write(pipefd[1], wrbuf, length);
> +		if (written > 0)
> +			tst_brkm(TBROK, cleanup, "write succeeded expectedly");
Did you mean "unexpectedly"?

>  	}
>  	cleanup();
>  	tst_exit();
> diff --git a/testcases/kernel/syscalls/pipe/pipe11.c b/testcases/kernel/syscalls/pipe/pipe11.c
> index e11c556..e3b2741 100644
> --- a/testcases/kernel/syscalls/pipe/pipe11.c
> +++ b/testcases/kernel/syscalls/pipe/pipe11.c
> @@ -198,7 +198,8 @@ void do_child_uclinux(void)
>   */
>  void setup(void)
>  {
> -	int i, j;
> +	int i;
> +	unsigned int j;

>  	tst_sig(FORK, DEF_HANDLER, cleanup);

> @@ -230,9 +231,8 @@ void setup(void)
>  	j = 0;
>  	for (i = 0; i < szcharbuf;) {
>  		wrbuf[i++] = rawchars[j++];
> -		if (j >= sizeof(rawchars)) {
> +		if (j >= sizeof(rawchars))
>  			j = 0;
> -		}
>  	}
>  }

Otherwise LGTM, thanks!


Kind regards,
Petr
Jinhui Huang March 6, 2018, 1:41 a.m. UTC | #2
于 2018/03/05 16:03, Petr Vorel 写道:
> Hi Jinhui,
>
>> Signed-off-by: Jinhui Huang<huangjh.jy@cn.fujitsu.com>
>> ---
>>   testcases/kernel/syscalls/pipe/pipe04.c | 2 +-
>>   testcases/kernel/syscalls/pipe/pipe05.c | 4 ++--
>>   testcases/kernel/syscalls/pipe/pipe07.c | 2 +-
>>   testcases/kernel/syscalls/pipe/pipe08.c | 2 ++
>>   testcases/kernel/syscalls/pipe/pipe11.c | 6 +++---
>>   5 files changed, 9 insertions(+), 7 deletions(-)
>> diff --git a/testcases/kernel/syscalls/pipe/pipe04.c b/testcases/kernel/syscalls/pipe/pipe04.c
>> index b3d255b..a3c56e3 100644
>> --- a/testcases/kernel/syscalls/pipe/pipe04.c
>> +++ b/testcases/kernel/syscalls/pipe/pipe04.c
>> @@ -235,7 +235,7 @@ void c2func(void)
>>   			tst_resm(TBROK | TERRNO, "[child 2] pipe write failed");
>>   }
>> -void alarmfunc(int sig)
>> +void alarmfunc(int sig LTP_ATTRIBUTE_UNUSED)
>>   {
>>   	/* for some reason tst_brkm doesn't seem to work in a signal handler */
>>   	tst_brkm(TFAIL, cleanup, "one or more children did't die in 60 second "
>> diff --git a/testcases/kernel/syscalls/pipe/pipe05.c b/testcases/kernel/syscalls/pipe/pipe05.c
>> index fe5ec37..4105988 100644
>> --- a/testcases/kernel/syscalls/pipe/pipe05.c
>> +++ b/testcases/kernel/syscalls/pipe/pipe05.c
>> @@ -59,7 +59,7 @@ void sig11_handler(int sig);
>>   int main(int ac, char **av)
>>   {
>> -	int lc;
>> +	volatile int lc;
> Why volatile?
>
Hi Petr,

The compiler warning:
pipe05.c: In function ‘main’:
pipe05.c:62:6: warning: variable ‘lc’ might be clobbered by ‘longjmp’ or 
‘vfork’ [-Wclobbered]
int lc;
We may avoid this warning by declaring "lc" as volatile which tells the 
optimizer not to optimize it.
>>   	struct sigaction sa, osa;
>>   	tst_parse_opts(ac, av, NULL, NULL);
>> @@ -120,7 +120,7 @@ void setup(void)
>>   /******************************************************************
>>    * sig11_handler() - our segfault recover hack
>>    ******************************************************************/
>> -void sig11_handler(int sig)
>> +void sig11_handler(int sig LTP_ATTRIBUTE_UNUSED)
>>   {
>>   	longjmp(sig11_recover, 1);
>>   }
>> diff --git a/testcases/kernel/syscalls/pipe/pipe07.c b/testcases/kernel/syscalls/pipe/pipe07.c
>> index b09df71..55bb9f4 100644
>> --- a/testcases/kernel/syscalls/pipe/pipe07.c
>> +++ b/testcases/kernel/syscalls/pipe/pipe07.c
>> @@ -129,7 +129,7 @@ static void record_open_fds(void)
>>   		if (fd == dir_fd)
>>   			continue;
>> -		if (rec_fds_max>= ARRAY_SIZE(rec_fds)) {
>> +		if (rec_fds_max>= (int)ARRAY_SIZE(rec_fds)) {
>>   			tst_brkm(TBROK, cleanup,
>>   			         "Too much file descriptors open");
>>   		}
>> diff --git a/testcases/kernel/syscalls/pipe/pipe08.c b/testcases/kernel/syscalls/pipe/pipe08.c
>> index cdb2a4d..9f8d9cc 100644
>> --- a/testcases/kernel/syscalls/pipe/pipe08.c
>> +++ b/testcases/kernel/syscalls/pipe/pipe08.c
>> @@ -98,6 +98,8 @@ int main(int ac, char **av)
>>   		 * sent
>>   		 */
>>   		written = write(pipefd[1], wrbuf, length);
>> +		if (written>  0)
>> +			tst_brkm(TBROK, cleanup, "write succeeded expectedly");
> Did you mean "unexpectedly"?
>
Yes.

Best regards,
Jinhui

>>   	}
>>   	cleanup();
>>   	tst_exit();
>> diff --git a/testcases/kernel/syscalls/pipe/pipe11.c b/testcases/kernel/syscalls/pipe/pipe11.c
>> index e11c556..e3b2741 100644
>> --- a/testcases/kernel/syscalls/pipe/pipe11.c
>> +++ b/testcases/kernel/syscalls/pipe/pipe11.c
>> @@ -198,7 +198,8 @@ void do_child_uclinux(void)
>>    */
>>   void setup(void)
>>   {
>> -	int i, j;
>> +	int i;
>> +	unsigned int j;
>>   	tst_sig(FORK, DEF_HANDLER, cleanup);
>> @@ -230,9 +231,8 @@ void setup(void)
>>   	j = 0;
>>   	for (i = 0; i<  szcharbuf;) {
>>   		wrbuf[i++] = rawchars[j++];
>> -		if (j>= sizeof(rawchars)) {
>> +		if (j>= sizeof(rawchars))
>>   			j = 0;
>> -		}
>>   	}
>>   }
> Otherwise LGTM, thanks!
>
>
> Kind regards,
> Petr
>
>
> .
>
Petr Vorel March 6, 2018, 3:03 p.m. UTC | #3
Hi Jinhui,

> > > Signed-off-by: Jinhui Huang<huangjh.jy@cn.fujitsu.com>
> > > ---
> > >   testcases/kernel/syscalls/pipe/pipe04.c | 2 +-
> > >   testcases/kernel/syscalls/pipe/pipe05.c | 4 ++--
> > >   testcases/kernel/syscalls/pipe/pipe07.c | 2 +-
> > >   testcases/kernel/syscalls/pipe/pipe08.c | 2 ++
> > >   testcases/kernel/syscalls/pipe/pipe11.c | 6 +++---
> > >   5 files changed, 9 insertions(+), 7 deletions(-)
...

> Hi Petr,

> The compiler warning:
> pipe05.c: In function ‘main’:
> pipe05.c:62:6: warning: variable ‘lc’ might be clobbered by ‘longjmp’ or
> ‘vfork’ [-Wclobbered]
> int lc;
> We may avoid this warning by declaring "lc" as volatile which tells the
> optimizer not to optimize it.
Thanks for info. This was issued by gcc-4.x, that's why I didn't notice that.
I pushed the patch, thanks!
BTW these tests deserve rewriting into new API, that would be a big improvement.


Kind regards,
Petr
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/pipe/pipe04.c b/testcases/kernel/syscalls/pipe/pipe04.c
index b3d255b..a3c56e3 100644
--- a/testcases/kernel/syscalls/pipe/pipe04.c
+++ b/testcases/kernel/syscalls/pipe/pipe04.c
@@ -235,7 +235,7 @@  void c2func(void)
 			tst_resm(TBROK | TERRNO, "[child 2] pipe write failed");
 }
 
-void alarmfunc(int sig)
+void alarmfunc(int sig LTP_ATTRIBUTE_UNUSED)
 {
 	/* for some reason tst_brkm doesn't seem to work in a signal handler */
 	tst_brkm(TFAIL, cleanup, "one or more children did't die in 60 second "
diff --git a/testcases/kernel/syscalls/pipe/pipe05.c b/testcases/kernel/syscalls/pipe/pipe05.c
index fe5ec37..4105988 100644
--- a/testcases/kernel/syscalls/pipe/pipe05.c
+++ b/testcases/kernel/syscalls/pipe/pipe05.c
@@ -59,7 +59,7 @@  void sig11_handler(int sig);
 
 int main(int ac, char **av)
 {
-	int lc;
+	volatile int lc;
 	struct sigaction sa, osa;
 
 	tst_parse_opts(ac, av, NULL, NULL);
@@ -120,7 +120,7 @@  void setup(void)
 /******************************************************************
  * sig11_handler() - our segfault recover hack
  ******************************************************************/
-void sig11_handler(int sig)
+void sig11_handler(int sig LTP_ATTRIBUTE_UNUSED)
 {
 	longjmp(sig11_recover, 1);
 }
diff --git a/testcases/kernel/syscalls/pipe/pipe07.c b/testcases/kernel/syscalls/pipe/pipe07.c
index b09df71..55bb9f4 100644
--- a/testcases/kernel/syscalls/pipe/pipe07.c
+++ b/testcases/kernel/syscalls/pipe/pipe07.c
@@ -129,7 +129,7 @@  static void record_open_fds(void)
 		if (fd == dir_fd)
 			continue;
 
-		if (rec_fds_max >= ARRAY_SIZE(rec_fds)) {
+		if (rec_fds_max >= (int)ARRAY_SIZE(rec_fds)) {
 			tst_brkm(TBROK, cleanup,
 			         "Too much file descriptors open");
 		}
diff --git a/testcases/kernel/syscalls/pipe/pipe08.c b/testcases/kernel/syscalls/pipe/pipe08.c
index cdb2a4d..9f8d9cc 100644
--- a/testcases/kernel/syscalls/pipe/pipe08.c
+++ b/testcases/kernel/syscalls/pipe/pipe08.c
@@ -98,6 +98,8 @@  int main(int ac, char **av)
 		 * sent
 		 */
 		written = write(pipefd[1], wrbuf, length);
+		if (written > 0)
+			tst_brkm(TBROK, cleanup, "write succeeded expectedly");
 	}
 	cleanup();
 	tst_exit();
diff --git a/testcases/kernel/syscalls/pipe/pipe11.c b/testcases/kernel/syscalls/pipe/pipe11.c
index e11c556..e3b2741 100644
--- a/testcases/kernel/syscalls/pipe/pipe11.c
+++ b/testcases/kernel/syscalls/pipe/pipe11.c
@@ -198,7 +198,8 @@  void do_child_uclinux(void)
  */
 void setup(void)
 {
-	int i, j;
+	int i;
+	unsigned int j;
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
@@ -230,9 +231,8 @@  void setup(void)
 	j = 0;
 	for (i = 0; i < szcharbuf;) {
 		wrbuf[i++] = rawchars[j++];
-		if (j >= sizeof(rawchars)) {
+		if (j >= sizeof(rawchars))
 			j = 0;
-		}
 	}
 }