mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
refactor: Avoid false-positive gcc warning
GCC 14.2.1 will complain about a dangling reference after replacing Span wiht std::span. This is a false-positive, because std::find does not return a reference. Remove the `&` to silence the warning. Also use ranges::find while touching the line. src/i2p.cpp:312:21: error: possibly dangling reference to a temporary [-Werror=dangling-reference] 312 | const auto& pos = std::find(kv.begin(), kv.end(), '='); | ^~~ src/i2p.cpp:312:36: note: the temporary was destroyed at the end of the full expression ‘std::find<__gnu_cxx::__normal_iterator<const char*, span<const char> >, char>((& kv)->std::span<const char>::begin(), (& kv)->std::span<const char>::end(), '=')’ 312 | const auto& pos = std::find(kv.begin(), kv.end(), '='); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors
This commit is contained in:
parent
fa942332b4
commit
fa4d6ec97b
1 changed files with 3 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2020-2022 The Bitcoin Core developers
|
// Copyright (c) 2020-present The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <ranges>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -309,7 +310,7 @@ Session::Reply Session::SendRequestAndGetReply(const Sock& sock,
|
||||||
reply.full = sock.RecvUntilTerminator('\n', recv_timeout, *m_interrupt, MAX_MSG_SIZE);
|
reply.full = sock.RecvUntilTerminator('\n', recv_timeout, *m_interrupt, MAX_MSG_SIZE);
|
||||||
|
|
||||||
for (const auto& kv : Split(reply.full, ' ')) {
|
for (const auto& kv : Split(reply.full, ' ')) {
|
||||||
const auto& pos = std::find(kv.begin(), kv.end(), '=');
|
const auto pos{std::ranges::find(kv, '=')};
|
||||||
if (pos != kv.end()) {
|
if (pos != kv.end()) {
|
||||||
reply.keys.emplace(std::string{kv.begin(), pos}, std::string{pos + 1, kv.end()});
|
reply.keys.emplace(std::string{kv.begin(), pos}, std::string{pos + 1, kv.end()});
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue