Skip to contentSkip to conversation

libpci: ecam: Fix discards const from pointer target

PATCH In review Rudi Heitbaum 2 participants 2 messages Feb 22 – Apr 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libpci: ecam: Fix discards const from pointer target

endptr is used as the return from strchr(addrs, ',') which is a const char. endptr is subsequently used as a pointer to the token which is char. Fix by not reusing endptr, but declare addrsptr as a const char * pointer for use in the first case addressing the warning.

fixes:
ecam.c: In function 'parse_next_addrs':
ecam.c:620:10: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
620 | endptr = strchr(addrs, ',');
| ^

---
 lib/ecam.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/ecam.c +5 -5
index de8ecb5..65edd82 100644
@@ -603,7 +603,7 @@ static int
 parse_next_addrs(const char *addrs, const char **next, int *domain, u8 *start_bus, u8 *end_bus, u64 *addr, u32 *length)
 {
   u64 ullnum;
-  const char *sep1, *sep2;
+  const char *addrsptr, *sep1, *sep2;
   int addr_len;
   char *endptr;
   long num;
@@ -617,14 +617,14 @@ parse_next_addrs(const char *addrs, const char **next, int *domain, u8 *start_bu
       return 0;
     }
 
-  endptr = strchr(addrs, ',');
-  if (endptr)
-    addr_len = endptr - addrs;
+  addrsptr = strchr(addrs, ',');
+  if (addrsptr)
+    addr_len = addrsptr - addrs;
   else
     addr_len = strlen(addrs);
 
   if (next)
-    *next = endptr ? (endptr+1) : NULL;
+    *next = addrsptr ? (addrsptr+1) : NULL;
 
   sep1 = memchr(addrs, ':', addr_len);
   if (!sep1)
Signature · 1 line
2.51.0
#1 lore raw

Hi!

Quoted 4 lines

endptr is used as the return from strchr(addrs, ',') which is a const char. endptr is subsequently used as a pointer to the token which is char. Fix by not reusing endptr, but declare addrsptr as a const char * pointer for use in the first case addressing the warning.

[...]

Thanks, both patches applied.

Have a nice day

Signature · 2 lines
Martin `MJ' Mareš                        <[email protected]>   http://mj.ucw.cz/
United Computer Wizards, Prague, Czech Republic, Europe, Earth, Universe