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);
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);