Skip to content

serialize string length error! #214

@daohu527

Description

@daohu527

@rojkov std::string may contain '\0', so should we pass str.size() to serialize?

inline
FastCdr& serialize(
const std::string& string_t)
{
return serialize(string_t.c_str());
}

Below is the test code

#include <iostream>
#include <string>
#include <cstring>

int main()
{
    const char* c_str = "Hello\0World";
    std::string str(c_str, 11);
    
    std::cout << str.size() << std::endl;           // 11
    std::cout << strlen(str.c_str()) << std::endl;  // 5

    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions