]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/build] Use const_cast in fd_copy
authorTom de Vries <tdevries@suse.de>
Mon, 6 Jan 2025 08:53:26 +0000 (09:53 +0100)
committerTom de Vries <tdevries@suse.de>
Mon, 6 Jan 2025 08:53:26 +0000 (09:53 +0100)
Recent commit 6ab5d62ebc5 ("[gdb] Fix compilation error in event-top.c") did:
...
 fd_copy (fd_set *dst, const fd_set *src, int n)
 {
   FD_ZERO (dst);
   for (int i = 0; i < n; ++i)
-    if (FD_ISSET (i, src))
+    if (FD_ISSET (i, (fd_set *)src))
...
but according to [1] only const_cast may be used to cast away constness.

Fix this by using const_cast.

Tested by rebuilding on x86_64-linux.

[1] https://en.cppreference.com/w/cpp/language/const_cast

gdb/event-top.c

index 5fa53bf8bdc09f79ac44f4423263b131654db924..1fe37841935655808efe72afdd01a8565eda20cd 100644 (file)
@@ -1276,7 +1276,7 @@ fd_copy (fd_set *dst, const fd_set *src, int n)
 {
   FD_ZERO (dst);
   for (int i = 0; i < n; ++i)
-    if (FD_ISSET (i, (fd_set *)src))
+    if (FD_ISSET (i, const_cast<fd_set *>(src)))
       FD_SET (i, dst);
 
   return dst;