wiphy: Relpace rawmemchr with memchr
PATCH 1/1 wiphy: Relpace rawmemchr with memchr
The rawmemchr function is a GNU extension, and not available in other libc implementations, such as musl.
--- src/wiphy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/wiphy.c +1 -1
@@ -500,7 +500,7 @@ const uint8_t *wiphy_get_supported_rates(struct wiphy *wiphy, unsigned int band,if (out_num) *out_num = - (uint8_t *)rawmemchr (wiphy->supported_rates[band],0 ) - + (uint8_t *)memchr (wiphy->supported_rates[band],0 , (size_t )-1 ) - wiphy->supported_rates[band];return wiphy->supported_rates[band];
Signature · 1 line
2.24.1
Hi Robert,
Quoted 12 lines · Robert Joslyn
The rawmemchr function is a GNU extension, and not available in other libc implementations, such as musl.
--- src/wiphy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/wiphy.c +0
-0
src/wiphy.c const uint8_t *wiphy_get_supported_rates(struct wiphy *wiphy, unsigned int band, · line 506
Quoted 8 lines
src/wiphy.c +1
-1@@ -500,7 +500,7 @@ const uint8_t *wiphy_get_supported_rates(struct wiphy *wiphy, unsigned int band,if (out_num) *out_num = - (uint8_t *)rawmemchr (wiphy->supported_rates[band],0 ) - + (uint8_t *)memchr (wiphy->supported_rates[band],0 , (size_t )-1 ) - wiphy->supported_rates[band];return wiphy->supported_rates[band];
Unfortunately this causes gcc to complain:
src/wiphy.c: In function ‘wiphy_get_supported_rates’:src/wiphy.c:503:16: error: ‘memchr’ specified size 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
503 | (uint8_t *) memchr(wiphy->supported_rates[band], 0,
(size_t)-1) -
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
can you try the attached patch instead?
Regards,
-Denis
From fcdddf2b726439e049992878f90da607414a1a47 Mon Sep 17 00:00:00 2001
From: Denis Kenzior <[email protected]>
Date: Mon, 3 Feb 2020 11:54:28 -0600
Subject: [PATCH] build: Support missing rawmemchr
--- configure.ac | 1 + src/missing.h | 10 ++++++++++ src/wiphy.c | 1 + 3 files changed, 12 insertions(+)
configure.ac +1 -0
@@ -128,6 +128,7 @@ AC_DEFINE_UNQUOTED(WIRED_STORAGEDIR, "${wired_storagedir}", [Directory for Ethernet daemon storage files]) AC_CHECK_FUNCS(explicit_bzero) +AC_CHECK_FUNCS(rawmemchr) AC_CHECK_HEADERS(linux/types.h linux/if_alg.h)
src/missing.h +10 -0
@@ -27,3 +27,13 @@ static inline void explicit_bzero(void *s, size_t n) __asm__ __volatile__ ("" : :"r" (s) :"memory" ); }#endif + +#ifndef HAVE_RAWMEMCHR +static inline void *rawmemchr (const void *s,int c) +{ +_Pragma("GCC diagnostic push") +_Pragma("GCC diagnostic ignored \"-Wstringop-overflow=\"") +return memchr (s, c, (size_t )-1 ); +_Pragma("GCC diagnostic pop") +} +#endif
src/wiphy.c +1 -0
@@ -37,6 +37,7 @@#include "linux/nl80211.h" +#include "src/missing.h" #include "src/iwd.h" #include "src/module.h" #include "src/ie.h"
Signature · 1 line
2.21.0
Quoted 35 lines · Denis Kenzior
Hi Robert,
Quoted 21 lines · Robert Joslyn
The rawmemchr function is a GNU extension, and not available in other libc implementations, such as musl.
--- src/wiphy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/wiphy.c +0
-1@@ -500,7 +500,7 @@ const uint8_t *wiphy_get_supported_rates(struct wiphy *wiphy, unsigned int band, if (out_num) *out_num = - (uint8_t *) rawmemchr(wiphy-Quoted 1 line
supported_rates[band], 0) -
src/wiphy.c +1
-0+ (uint8_t *) memchr(wiphy->supported_rates[band],0, (size_t)-1) -
wiphy->supported_rates[band];Quoted 2 lines
return wiphy->supported_rates[band];Unfortunately this causes gcc to complain:
src/wiphy.c: In function ‘wiphy_get_supported_rates’:src/wiphy.c:503:16: error: ‘memchr’ specified size 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop- overflow=]
503 | (uint8_t*) memchr(wiphy->supported_rates[band], 0,
(size_t)-1) -
Quoted 7 lines
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
can you try the attached patch instead?
Regards,
-Denis
Hi Denis,
Sorry about that. I'm doing my builds with Yocto/OpenEmbedded (master branch) and was able to build with both glibc and musl with my original patch, but compile flags or gcc version are probably different.
Your patch works fine for me and looks like a better approach.
This got me curious, so I looked at what glibc does:
http://sourceware.org/git/?p=glibc.git;a=blob;f=string/rawmemchr.c;h=b62d285d7efa882b3928fae03318273d588f15bd;hb=HEAD
I expect the use of strlen when looking for null is slightly faster, but probably doesn't really matter here.
Thanks for taking a look and working on a fix!
Robert
Hi Robert,
Quoted 1 line
Your patch works fine for me and looks like a better approach.
Great! Thanks for testing.
Quoted 6 lines
This got me curious, so I looked at what glibc does:
http://sourceware.org/git/?p=glibc.git;a=blob;f=string/rawmemchr.c;h=b62d285d7efa882b3928fae03318273d588f15bd;hb=HEADI expect the use of strlen when looking for null is slightly faster, but probably doesn't really matter here.
Yeah, strlen might be a bit faster indeed. But I was feeling lazy and this isn't used for anything performance critical. :)
Quoted 3 lines
Thanks for taking a look and working on a fix!
No worries. I pushed out this fix upstream now.
Regards,
-Denis