Skip to content

fix: replace deprecated <strstream> with <sstream> in porthopper example#1755

Open
mvanhorn wants to merge 1 commit into
chriskohlhoff:masterfrom
mvanhorn:fix/1725-replace-deprecated-strstream
Open

fix: replace deprecated <strstream> with <sstream> in porthopper example#1755
mvanhorn wants to merge 1 commit into
chriskohlhoff:masterfrom
mvanhorn:fix/1725-replace-deprecated-strstream

Conversation

@mvanhorn

Copy link
Copy Markdown

Summary

In protocol.hpp, replace #include <strstream> with #include <sstream>. Replace each std::istrstream is(ptr, len) with std::istringstream is(std::string(ptr, len)), and each std::ostrstream os(data_, N) with a local std::ostringstream os, followed by os.str().copy(data_, N) (after checking os state) so the fixed data_ buffer receives exactly the same setw-padded bytes as before; no interfaces of control_request or frame change, so client.cpp and server.cpp need no edits and serve as the compile/behavior surface. Graveyard delta vs closed PR #1729: that PR was auto-generated by a bot app and was closed unreviewed with zero comments (the issue author himself asked what happened to it); this plan is a human-authored minimal diff that avoids #1729's raw std::memcpy (which requires a <cstring> include and risks copying fewer bytes than the buffer on a failed stream) by using std::string::copy with explicit stream-state and length checks, and it documents that the on-wire format is unchanged.

Why this matters

The C++11 porthopper example includes <strstream> and uses std::istrstream / std::ostrstream in src/examples/cpp11/porthopper/protocol.hpp. <strstream> has been deprecated since C++98 and is removed in C++26 per P2867R1, so GCC 16 emits -Wdeprecated-declarations and #warning noise at lines 56, 65, 84, 115, and 124, and the example will stop compiling under C++26. The reporter (heitbaum, LibreELEC) hit this building the examples with a GCC 16 toolchain. The fix is to switch the header to <sstream> with std::istringstream / std::ostringstream while keeping the fixed-width, space-padded wire encoding byte-identical.

See #1725.

Testing

  • Happy path: build the cpp11 porthopper example (client.cpp, server.cpp) with a current GCC/Clang at -Wall; compiles with no deprecated-header or deprecated-declaration warnings. - Round-trip: run server and client locally; frames and control requests decode the same port/frame numbers that were encoded, confirming the space-padded fixed-width encoding is byte-identical to the strstream version. - Edge cases: encode port 0 and 65535, frame number 0 and a large value; decoded values match and encoded fields remain exactly encoded_port_size / encoded_number_size bytes. - Error path: stream failure during encode (value too wide for the field) leaves the object in the same defined state as before; decode of short/garbage input fails gracefully as it did with istrstream.

Fixes #1725

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

Successfully merging this pull request may close these issues.

C++11 example using deprecated <strstream> replace with <sstream>?

1 participant