[v2] change type of variable to fix compile warning

Message ID 20180609030106.3927-1-sunlw.fnst@cn.fujitsu.com
State Changes Requested
Delegated to: Petr Vorel
Headers show
Series
  • [v2] change type of variable to fix compile warning
Related show

Commit Message

Sun Lianwen June 9, 2018, 3:01 a.m.
Change the type of variable from int to unsigned intto fix complie 
warning: "comparison between signed and unsigned integer expressions [-Wsign-compare]"

Signed-off-by: Sun Lianwen <sunlw.fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/move_pages/move_pages_support.c | 2 +-
 testcases/kernel/syscalls/symlink/symlink01.c             | 2 +-
 utils/benchmark/ebizzy-0.3/ebizzy.c                       | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)

Comments

Petr Vorel June 15, 2018, 6:18 a.m. | #1
Hi Sun,

> Change the type of variable from int to unsigned intto fix complie 
> warning: "comparison between signed and unsigned integer expressions [-Wsign-compare]"

> Signed-off-by: Sun Lianwen <sunlw.fnst@cn.fujitsu.com>

You left some of the comparison warnings, can you please fix them?
move_pages_support.c: In function ‘alloc_pages_on_nodes’:
move_pages_support.c:70:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < num; i++) {
                ^
move_pages_support.c:74:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < num; i++) {
                ^
move_pages_support.c:91:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (i == num)
        ^~
symlink01.c: In function ‘get_tcs_info’:
symlink01.c:601:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (ctr = 0; ctr < (sizeof(all_tcses) / sizeof(struct tcses)); ctr++) {
                    ^

ebizzy.c: In function ‘thread_run’:
ebizzy.c:424:31: warning: unused parameter ‘arg’ [-Wunused-parameter]
 static void *thread_run(void *arg)
This one can be fixed with LTP_ATTRIBUTE_UNUSED
+#include "tst_common.h"
                               ^~~
-static void *thread_run(void *arg)
+static void *thread_run(void *arg LTP_ATTRIBUTE_UNUSED)


Kind regards,
Petr
Sun Lianwen June 15, 2018, 6:25 a.m. | #2
Hi Petr,

On 06/15/2018 02:18 PM, Petr Vorel wrote:
> Hi Sun,
> 
>> Change the type of variable from int to unsigned intto fix complie 
>> warning: "comparison between signed and unsigned integer expressions [-Wsign-compare]"
> 
>> Signed-off-by: Sun Lianwen <sunlw.fnst@cn.fujitsu.com>
> 
> You left some of the comparison warnings, can you please fix them?
Thanks your advise, I will fix the left comparison warnings.
> move_pages_support.c: In function ‘alloc_pages_on_nodes’:
> move_pages_support.c:70:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
>   for (i = 0; i < num; i++) {
>                 ^
> move_pages_support.c:74:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
>   for (i = 0; i < num; i++) {
>                 ^
> move_pages_support.c:91:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
>   if (i == num)
>         ^~
> symlink01.c: In function ‘get_tcs_info’:
> symlink01.c:601:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
>   for (ctr = 0; ctr < (sizeof(all_tcses) / sizeof(struct tcses)); ctr++) {
>                     ^
> 
> ebizzy.c: In function ‘thread_run’:
> ebizzy.c:424:31: warning: unused parameter ‘arg’ [-Wunused-parameter]
>  static void *thread_run(void *arg)
> This one can be fixed with LTP_ATTRIBUTE_UNUSED
> +#include "tst_common.h"
>                                ^~~
> -static void *thread_run(void *arg)
> +static void *thread_run(void *arg LTP_ATTRIBUTE_UNUSED)
> 
> 
> Kind regards,
> Petr
> 
> 
> .
> 
Thanks
Sun Lianwen

Patch

diff --git a/testcases/kernel/syscalls/move_pages/move_pages_support.c b/testcases/kernel/syscalls/move_pages/move_pages_support.c
index 610f570d0..77dfd07f2 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages_support.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages_support.c
@@ -62,7 +62,7 @@  void free_pages(void **pages, unsigned int num)
  */
 int alloc_pages_on_nodes(void **pages, unsigned int num, int *nodes)
 {
-	int i;
+	unsigned int i;
 #ifdef HAVE_NUMA_V2
 	size_t onepage = get_page_size();
 #endif
diff --git a/testcases/kernel/syscalls/symlink/symlink01.c b/testcases/kernel/syscalls/symlink/symlink01.c
index 03a51a5cb..50805f7bb 100644
--- a/testcases/kernel/syscalls/symlink/symlink01.c
+++ b/testcases/kernel/syscalls/symlink/symlink01.c
@@ -584,7 +584,7 @@  int main(int argc, char *argv[])
  ***********************************************************************/
 struct tcses *get_tcs_info(char *ptr)
 {
-	int ctr;
+	unsigned int ctr;
 	struct tcses *tcs_ptr;
 
 #if ALL
diff --git a/utils/benchmark/ebizzy-0.3/ebizzy.c b/utils/benchmark/ebizzy-0.3/ebizzy.c
index 5bb8eff56..8a433e8e1 100644
--- a/utils/benchmark/ebizzy-0.3/ebizzy.c
+++ b/utils/benchmark/ebizzy-0.3/ebizzy.c
@@ -228,7 +228,7 @@  static void read_options(int argc, char *argv[])
 
 static void touch_mem(char *dest, size_t size)
 {
-	int i;
+	unsigned int i;
 	if (touch_pages) {
 		for (i = 0; i < size; i += page_size)
 			*(dest + i) = 0xff;
@@ -279,7 +279,7 @@  static void my_memcpy(void *dest, void *src, size_t len)
 {
 	char *d = (char *)dest;
 	char *s = (char *)src;
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < len; i++)
 		d[i] = s[i];
@@ -288,7 +288,7 @@  static void my_memcpy(void *dest, void *src, size_t len)
 
 static void allocate(void)
 {
-	int i;
+	unsigned int i;
 
 	mem = alloc_mem(chunks * sizeof(record_t *));
 
@@ -313,7 +313,7 @@  static void allocate(void)
 
 static void write_pattern(void)
 {
-	int i, j;
+	unsigned int i, j;
 
 	for (i = 0; i < chunks; i++) {
 		for (j = 0; j < chunk_size / record_size; j++)