const char *strSource
)
{
- if(std::strlen(strSource)+1 > sizeInBytes)
+ std::size_t lenSourceWithNull = std::strlen(strSource) + 1;
+ if (lenSourceWithNull > sizeInBytes)
return 1;
- std::strcpy(strDestination, strSource);
+ std::memcpy(strDestination, strSource, lenSourceWithNull);
return 0;
}
inline std::size_t strcat_s(
const char *strSource
)
{
- if(std::strlen(strSource) + std::strlen(strDestination) + 1 > sizeInBytes)
+ std::size_t lenSourceWithNull = std::strlen(strSource) + 1;
+ std::size_t lenDestination = std::strlen(strDestination);
+ if (lenSourceWithNull + lenDestination > sizeInBytes)
return 1;
- std::strcat(strDestination, strSource);
+ std::memcpy(strDestination + lenDestination, strSource, lenSourceWithNull);
return 0;
}