mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-11 15:22:13 +03:00
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])
This commit is contained in:
@ -61,6 +61,7 @@ class Stream: public Print {
|
||||
virtual int peek() = 0;
|
||||
|
||||
Stream() {}
|
||||
virtual ~Stream() {}
|
||||
|
||||
// parsing methods
|
||||
|
||||
|
@ -160,6 +160,7 @@ protected:
|
||||
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)) { }
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user