Skip to content

Commit dde2c76

Browse files
authored
StreamConstPtr: disallow passing a String temporary (#8410)
* StreamConstPtr: prevent from passing a temporary String instance * unconditionally allow progmem chars * missing virtual destructor in Stream (warning: deleting object of abstract class type 'Stream' which has non-virtual destructor will cause undefined behavior [-Wdelete-non-virtual-dtor])
1 parent e3c79de commit dde2c76

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

cores/esp8266/Stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Stream: public Print {
6161
virtual int peek() = 0;
6262

6363
Stream() {}
64+
virtual ~Stream() {}
6465

6566
// parsing methods
6667

cores/esp8266/StreamDev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class StreamConstPtr: public StreamNull
160160
size_t _peekPointer = 0;
161161

162162
public:
163+
StreamConstPtr(const String&& string) = delete; // prevents passing String temporary, use ctor(buffer,size) if you know what you are doing
163164
StreamConstPtr(const String& string): _buffer(string.c_str()), _size(string.length()), _byteAddressable(true) { }
164165
StreamConstPtr(const char* buffer, size_t size): _buffer(buffer), _size(size), _byteAddressable(__byteAddressable(buffer)) { }
165166
StreamConstPtr(const uint8_t* buffer, size_t size): _buffer((const char*)buffer), _size(size), _byteAddressable(__byteAddressable(buffer)) { }

cores/esp8266/StreamSend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Stream& operator << (Stream& out, Stream& stream)
341341

342342
Stream& operator << (Stream& out, const char* text)
343343
{
344-
StreamConstPtr(text).sendAll(out);
344+
StreamConstPtr(text, strlen_P(text)).sendAll(out);
345345
return out;
346346
}
347347

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy