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

Moving one EthernetClient object to another crashes the Portenta H7 #715

Open
xmkg opened this issue Aug 24, 2023 · 2 comments
Open

Moving one EthernetClient object to another crashes the Portenta H7 #715

xmkg opened this issue Aug 24, 2023 · 2 comments

Comments

@xmkg
Copy link

xmkg commented Aug 24, 2023

As the title says. Reproducer sketch:

#include <Ethernet.h>

// --------------------------------------------------------------------------------
// remove_reference

template<typename T>
struct remove_reference {
  typedef T type;
};

template<typename T>
struct remove_reference<T &> {
  typedef T type;
};

template<typename T>
struct remove_reference<T &&> {
  typedef T type;
};


#define MOVE(...) \
  static_cast<typename remove_reference<decltype(__VA_ARGS__)>::type &&>( \
    __VA_ARGS__)


void setup() {
  EthernetClient ec = {};
  EthernetClient ec2{ MOVE(ec) };  // Crashes the board
}

void loop() {}
@xmkg
Copy link
Author

xmkg commented Aug 24, 2023

It seems like it's not exclusive to moving. Copying also has the same effect:

void setup() {
  EthernetClient ec = {};
  EthernetClient ec2{ ec };  // Crashes the board
}

@hwmaier
Copy link

hwmaier commented Nov 6, 2023

I have the same issue with verion 4.0.8.

I believe this bug makes it impossible to use the Ethernet server accepting Ethernet client connections using the standard implementation:

        client = server.available();
        if (client) {
           ...

which tries to return an EthernetClient object from the available() call which is internally created using a copy constructor.

I tracked it down to arduino::MbedClient::setSocket() trying to configure a nullptr socket with this possible fix:

void arduino::MbedClient::setSocket(Socket *_sock) {
  sock = _sock;
  if (sock != nullptr) // Configure only if not null
      configureSocket(sock);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants