Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC 14: Werror=dangling-pointer in uu_list.c #16124

Closed
tonyhutter opened this issue Apr 24, 2024 · 0 comments
Closed

GCC 14: Werror=dangling-pointer in uu_list.c #16124

tonyhutter opened this issue Apr 24, 2024 · 0 comments
Labels
Type: Defect Incorrect behavior (e.g. crash, hang)

Comments

@tonyhutter
Copy link
Contributor

System information

Type Version/Name
Distribution Name Fedora
Distribution Version 40
Kernel Version 6.8.7-300
Architecture x86-64
OpenZFS Version master 1f940de

Describe the problem you're observing

GCC 14 on Fedora 40 gives dangling pointer error.

Describe how to reproduce the problem

make on F40

Include any warning/errors/backtraces from the system logs

  CC       lib/libuutil/libuutil_la-uu_list.lo
In function 'list_walk_init',
    inlined from 'uu_list_walk' at lib/libuutil/uu_list.c:511:3:
lib/libuutil/uu_list.c:419:32: error: storing the address of local variable 'my_walk' in '((uu_list_walk_t *)((char *)lp + 32))[1].ulw_prev' [-Werror=dangling-pointer=]
  419 |                 next->ulw_prev = wp;
      |                 ~~~~~~~~~~~~~~~^~~~
lib/libuutil/uu_list.c: In function 'uu_list_walk':
lib/libuutil/uu_list.c:508:32: note: 'my_walk' declared here
  508 |                 uu_list_walk_t my_walk;
      |                                ^~~~~~~
lib/libuutil/uu_list.c:493:25: note: 'lp' declared here
  493 | uu_list_walk(uu_list_t *lp, uu_walk_fn_t *func, void *private, uint32_t flags)
      |              ~~~~~~~~~~~^~
cc1: all warnings being treated as errors

A naive glance makes me think the my_walk variable being dangled is only used on a debug codepath:

       if (lp->ul_debug || robust) {                                             
              uu_list_walk_t my_walk;                                            
              void *e;                                                           
                                                                                 
              list_walk_init(&my_walk, lp, flags);                               
              while (status == UU_WALK_NEXT &&                                   
                  (e = uu_list_walk_next(&my_walk)) != NULL)                     
                     status = (*func)(e, private);                               
              list_walk_fini(&my_walk);                                          
       } else {

Workaround:

diff --git a/lib/libuutil/uu_list.c b/lib/libuutil/uu_list.c
index 0ca6f0520..659f8db41 100644
--- a/lib/libuutil/uu_list.c
+++ b/lib/libuutil/uu_list.c
@@ -416,8 +416,11 @@ list_walk_init(uu_list_walk_t *wp, uu_list_t *lp, uint32_t flags)
                 */
                wp->ulw_next = next = &lp->ul_null_walk;
                wp->ulw_prev = prev = next->ulw_prev;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer="
                next->ulw_prev = wp;
                prev->ulw_next = wp;
+#pragma GCC diagnostic pop
        }
 }
@tonyhutter tonyhutter added the Type: Defect Incorrect behavior (e.g. crash, hang) label Apr 24, 2024
tonyhutter added a commit that referenced this issue May 2, 2024
- Workaround dangling pointer in uu_list.c (#16124)
- Fix calloc() transposed arguments in zpool_vdev_os.c
- Make some temp variables unsigned to prevent triggering a
  '-Werror=alloc-size-larger-than' error.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes #16124
Closes #16125
lundman pushed a commit to openzfsonwindows/openzfs that referenced this issue Sep 4, 2024
- Workaround dangling pointer in uu_list.c (openzfs#16124)
- Fix calloc() transposed arguments in zpool_vdev_os.c
- Make some temp variables unsigned to prevent triggering a
  '-Werror=alloc-size-larger-than' error.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes openzfs#16124
Closes openzfs#16125
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Defect Incorrect behavior (e.g. crash, hang)
Projects
None yet
Development

No branches or pull requests

1 participant