Skip to content

StreamConstPtr: disallow passing a String temporary #8410

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

Merged
merged 5 commits into from
Jan 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/esp8266/Stream.h
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ class Stream: public Print {
virtual int peek() = 0;

Stream() {}
virtual ~Stream() {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not mentioned?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commitlog added in OP


// parsing methods

1 change: 1 addition & 0 deletions cores/esp8266/StreamDev.h
Original file line number Diff line number Diff line change
@@ -160,6 +160,7 @@ class StreamConstPtr: public StreamNull
size_t _peekPointer = 0;

public:
StreamConstPtr(const String&& string) = delete; // prevents passing String temporary, use ctor(buffer,size) if you know what you are doing
StreamConstPtr(const String& string): _buffer(string.c_str()), _size(string.length()), _byteAddressable(true) { }
StreamConstPtr(const char* buffer, size_t size): _buffer(buffer), _size(size), _byteAddressable(__byteAddressable(buffer)) { }
StreamConstPtr(const uint8_t* buffer, size_t size): _buffer((const char*)buffer), _size(size), _byteAddressable(__byteAddressable(buffer)) { }
2 changes: 1 addition & 1 deletion cores/esp8266/StreamSend.cpp
Original file line number Diff line number Diff line change
@@ -341,7 +341,7 @@ Stream& operator << (Stream& out, Stream& stream)

Stream& operator << (Stream& out, const char* text)
{
StreamConstPtr(text).sendAll(out);
StreamConstPtr(text, strlen_P(text)).sendAll(out);
return out;
}