arduino / ArduinoCore-avr

The Official Arduino AVR core
https://www.arduino.cc
1.25k stars 1.06k forks source link

Wstring: getBytes() method is not clear to use with passing number of bytes to fill in buffer #537

Open Croody opened 1 year ago

Croody commented 1 year ago

When we pass buffer size to getBytes() accordingly to declared array size (buffer[bufSize]) then last index will be null. We must explicitly pass to getBytes() value [bufSize + 1] to properly get all bytes. This is not clear to use without take a look inside to getBytes() method. For example: String text{ "ABCDE" }; uint8_t buffer[text.length()] = {}; text.getBytes(buffer, text.length() + 1);