mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-24 13:53:36 +02:00
check malloc return value for NULL and update docs
`sfFtpDirectoryResponse_getDirectory` can fail and return NULL becuase 'strdup' returns null on failure but `sfFtpDirectoryResponse_getDirectoryUnicode` didn't and just had UB due not checking return value of malloc. typing NULL in the docs made me age 30 years btw
This commit is contained in:
1 parent
6ce8f95553
commit
66e7af4993
2 files changed
+4
-2
No files matched your search
@@ -225,7 +225,7 @@ CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getMessage(const sfFtpDirec
|
||||
///
|
||||
/// \param ftpDirectoryResponse Ftp directory response
|
||||
///
|
||||
/// \return Directory name
|
||||
/// \return Directory name or NULL if it failed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getDirectory(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
@@ -239,7 +239,7 @@ CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getDirectory(const sfFtpDir
|
||||
///
|
||||
/// \param ftpDirectoryResponse Ftp directory response
|
||||
///
|
||||
/// \return Directory name
|
||||
/// \return Directory name or NULL if it failed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfChar32* sfFtpDirectoryResponse_getDirectoryUnicode(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
|
||||
@@ -51,6 +51,8 @@ static_assert(alignof(sfChar32) == alignof(char32_t));
|
||||
{
|
||||
const std::size_t byteCount = sizeof(sfChar32) * str.getSize();
|
||||
auto* utf32 = static_cast<sfChar32*>(std::malloc(byteCount + sizeof(sfChar32)));
|
||||
if (!utf32)
|
||||
return nullptr;
|
||||
std::memcpy(utf32, str.getData(), byteCount);
|
||||
utf32[str.getSize()] = 0;
|
||||
|
||||
|
||||
Reference in new issue
Block a user