You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2023/01/18 10:51:37 UTC

[GitHub] [nuttx] jlaitine opened a new pull request, #8176: Build warning fixes

jlaitine opened a new pull request, #8176:
URL: https://github.com/apache/nuttx/pull/8176

   ## Summary
   
   This removes some build warnings on printf formatters and void * arithmetic.
   
   ## Impact
   
   Only build warnings, no functional impact
   
   ## Testing
   
   Built for several platforms
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] jlaitine commented on a diff in pull request #8176: Build warning fixes

Posted by GitBox <gi...@apache.org>.
jlaitine commented on code in PR #8176:
URL: https://github.com/apache/nuttx/pull/8176#discussion_r1080851962


##########
mm/mempool/mempool_multiple.c:
##########
@@ -220,7 +220,7 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
   col = index - (row << mpool->dict_col_num_log2);
   if (mpool->dict[row] == NULL ||
       mpool->dict[row][col].addr != addr ||
-      blk - addr >= mpool->dict[row][col].size)
+      (FAR char *)blk - (FAR char *)addr >= mpool->dict[row][col].size)

Review Comment:
   sure it would! Cleanest solution is always first cast the void * to the real target type ptr and then do arithmetic. This also gives the compiler the opportunity to know the maximum result size. intptr_t usage is IMHO useless almost always, and just think about it's bit size (it is minimum the same size of pointer + 1 bit). It also doesn't exist on all platforms (not sure if posix enfoces the existence though, not going to check it up now...).
   
   With pointers it is always safe and portable to do pointer arithmetic, but not on void * since by the standard you can't (obviously because of size of void). But if you don't know the target type, you always get the same result as gcc extension by casting to char *. So changing void * arithmetic by casting the pointers to char * doesn't change the existing functionality.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] jlaitine commented on a diff in pull request #8176: Build warning fixes

Posted by GitBox <gi...@apache.org>.
jlaitine commented on code in PR #8176:
URL: https://github.com/apache/nuttx/pull/8176#discussion_r1073767626


##########
mm/mempool/mempool_multiple.c:
##########
@@ -220,7 +220,7 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
   col = index - (row << mpool->dict_col_num_log2);
   if (mpool->dict[row] == NULL ||
       mpool->dict[row][col].addr != addr ||
-      blk - addr >= mpool->dict[row][col].size)
+      (FAR char *)blk - (FAR char *)addr >= mpool->dict[row][col].size)

Review Comment:
   I am only using gcc, version depending on the target (different versions for x86, arm linux, arm embedded, SiFive's risc compilers). But the issue here is just that the compiler flags in NuttX CI doesn't enable warnings for non-standard gcc extensions. It might be a good idea to go through the default compiler settings and set warnings on for non-standard extensions (+ maybe use -Werror in addition).
   
   Strictly standard following flags would be "-ansi -pedantic -Wall". Just to enable warning on void * arithmetic (which is btw forbidden in standards, but still has the gcc extension which treats it the same as arithmetic on char *) can be enabled individually in gcc with -Wpointer-arith
   
   Since I am working on PX4, and they use by default also -Werror (which I think is a good idea, warnings might go unnoticed otherwise), fixing these is important...
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #8176: Build warning fixes

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #8176:
URL: https://github.com/apache/nuttx/pull/8176#discussion_r1080643434


##########
mm/mempool/mempool_multiple.c:
##########
@@ -220,7 +220,7 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
   col = index - (row << mpool->dict_col_num_log2);
   if (mpool->dict[row] == NULL ||
       mpool->dict[row][col].addr != addr ||
-      blk - addr >= mpool->dict[row][col].size)
+      (FAR char *)blk - (FAR char *)addr >= mpool->dict[row][col].size)

Review Comment:
   Will `intptr_t` solve sign issue?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] jlaitine commented on a diff in pull request #8176: Build warning fixes

Posted by GitBox <gi...@apache.org>.
jlaitine commented on code in PR #8176:
URL: https://github.com/apache/nuttx/pull/8176#discussion_r1073475284


##########
mm/mempool/mempool_multiple.c:
##########
@@ -220,7 +220,7 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
   col = index - (row << mpool->dict_col_num_log2);
   if (mpool->dict[row] == NULL ||
       mpool->dict[row][col].addr != addr ||
-      blk - addr >= mpool->dict[row][col].size)
+      (FAR char *)blk - (FAR char *)addr >= mpool->dict[row][col].size)

Review Comment:
   yes, but then you'd need to do something like (ssize_t)((uintptr_t)blk - (uintptr_t)addr) . otherwise the sign of the calculation may be wrong (never negative but overflown to large positive) as it is compared against unsigned. and this format just looks even uglier (and relies on the fact(?) that sizeof(ssize_t) == sizeof(uintptr_t). which is maybe so, but not by standard (ssize_t just needs to be large enough to cover the whole address area, there is no requirement for it to be exactly the same size... *if* it would be larger this would fail still....  Just keeping pointers as pointers when doing pointer arithmetic is IMHO  cleanest, and then you can also trust that the result is proper signed integer :)
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 merged pull request #8176: Build warning fixes

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #8176:
URL: https://github.com/apache/nuttx/pull/8176


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] jlaitine commented on a diff in pull request #8176: Build warning fixes

Posted by GitBox <gi...@apache.org>.
jlaitine commented on code in PR #8176:
URL: https://github.com/apache/nuttx/pull/8176#discussion_r1073767626


##########
mm/mempool/mempool_multiple.c:
##########
@@ -220,7 +220,7 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
   col = index - (row << mpool->dict_col_num_log2);
   if (mpool->dict[row] == NULL ||
       mpool->dict[row][col].addr != addr ||
-      blk - addr >= mpool->dict[row][col].size)
+      (FAR char *)blk - (FAR char *)addr >= mpool->dict[row][col].size)

Review Comment:
   I am only using gcc, version depending on the target (different versions for x86, arm linux, arm embedded, SiFive's risc compilers). But the issue here is just that the compiler flags in NuttX CI doesn't enable warnings for non-standard gcc extensions. It might be a good idea to go through the default compiler settings and set warnings on for non-standard extensions (+ maybe use -Werror in addition).
   
   A strictly standard following flags would be "-ansi -pedantic -Wall". Just to enable warning on void * arithmetic (which is btw forbidden in standards, but still has the gcc extension which treats it the same as arithmetic on char *) can be enabled individually in gcc with -Wpointer-arith
   
   Since I am working on PX4, and they use by default also -Werror (which I think is a good idea, warnings might go unnoticed otherwise), fixing these is important...
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #8176: Build warning fixes

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #8176:
URL: https://github.com/apache/nuttx/pull/8176#discussion_r1073452370


##########
mm/mempool/mempool_multiple.c:
##########
@@ -220,7 +220,7 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
   col = index - (row << mpool->dict_col_num_log2);
   if (mpool->dict[row] == NULL ||
       mpool->dict[row][col].addr != addr ||
-      blk - addr >= mpool->dict[row][col].size)
+      (FAR char *)blk - (FAR char *)addr >= mpool->dict[row][col].size)

Review Comment:
   Just an alternative is `uintptr_t`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #8176: Build warning fixes

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #8176:
URL: https://github.com/apache/nuttx/pull/8176#discussion_r1073576249


##########
mm/mempool/mempool_multiple.c:
##########
@@ -220,7 +220,7 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
   col = index - (row << mpool->dict_col_num_log2);
   if (mpool->dict[row] == NULL ||
       mpool->dict[row][col].addr != addr ||
-      blk - addr >= mpool->dict[row][col].size)
+      (FAR char *)blk - (FAR char *)addr >= mpool->dict[row][col].size)

Review Comment:
   @jlaitine which compiler are you using? Look like your compiler generate more warning than the official CI.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org