string: improve strndup documentation

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2025-02-20 09:11:00 +01:00
parent 442001f66b
commit 69f2c639cd

View File

@ -1935,7 +1935,8 @@ namespace stdex
/// This allows returned string to be fed into std::unique_ptr<T> for auto release. /// This allows returned string to be fed into std::unique_ptr<T> for auto release.
/// ///
/// \param[in] str String to duplicate. /// \param[in] str String to duplicate.
/// \param[in] count Number of code units in str. /// \param[in] count Number of code units in str. Duplicated string will have this number of code units allocated.
/// If str contains zero terminator, duplicated string will also be zero terminated.
/// ///
/// \return Pointer to duplicated string. Use delete[] operator to free the memory. /// \return Pointer to duplicated string. Use delete[] operator to free the memory.
/// ///
@ -1945,7 +1946,7 @@ namespace stdex
_In_ size_t count) _In_ size_t count)
{ {
T* dst = new T[count]; T* dst = new T[count];
strncpy(dst, count, str, SIZE_MAX); strncpy(dst, count, str, count);
return dst; return dst;
} }
@ -1955,7 +1956,8 @@ namespace stdex
/// In contrast with the stdlib C strdup, the memory is allocated using operator new T[]. /// In contrast with the stdlib C strdup, the memory is allocated using operator new T[].
/// This allows returned string to be fed into std::unique_ptr<T> for auto release. /// This allows returned string to be fed into std::unique_ptr<T> for auto release.
/// ///
/// \param[in] str String to duplicate. Must be zero-terminated. /// \param[in] str String to duplicate.
/// If str contains zero terminator, duplicated string will also be zero terminated.
/// ///
/// \return Pointer to duplicated string; or nullptr if str is nullptr. Use delete[] operator to free the memory. /// \return Pointer to duplicated string; or nullptr if str is nullptr. Use delete[] operator to free the memory.
/// ///