writing variable length strings gets a null terminator
This commit is contained in:
parent
5f98768a8a
commit
798fe44ca4
|
@ -390,18 +390,18 @@ void bufferstream::readString(std::string &str, const int fixed_length, const bo
|
|||
* @param str
|
||||
* @param fixed_length write this length to the stream, padding with null
|
||||
* if str is shorter than fixed_length. If 0, will write the unrestricted
|
||||
* contents of str.
|
||||
* contents of str, including it's null termination.
|
||||
* @param terminated If true, the last byte of fixed_length is guaranteed to
|
||||
* be a 0 (null) byte.
|
||||
*/
|
||||
void bufferstream::writeString(const std::string &str, const size_t fixed_length,
|
||||
const bool terminated)
|
||||
const bool terminated)
|
||||
{
|
||||
// fixed_length == 0 means dynamic length.
|
||||
bool fixed = fixed_length > 0 ? true : false;
|
||||
|
||||
// fixed length strings restricted to fixed_lengh characters
|
||||
size_t maxlen = fixed ? fixed_length : str.size();
|
||||
size_t maxlen = fixed ? fixed_length : str.size() + 1; // null terminated
|
||||
|
||||
// write no more of the string than is available
|
||||
size_t wrtlen = str.size() < maxlen ? str.size() : maxlen;
|
||||
|
|
Loading…
Reference in New Issue