Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use non-throwing new operator to allocate memory for sfObj_create / sfObj_copy #336

Open
ZXShady opened this issue Sep 17, 2024 · 0 comments
Labels
Milestone

Comments

@ZXShady
Copy link
Contributor

ZXShady commented Sep 17, 2024

sfSound* sfSound_create(const sfSoundBuffer* buffer)
{
    assert(buffer);
    return new sfSound{sf::Sound(buffer->This), buffer}; 
// what would happen if new throws?
}

best to replace it with new(std::nothrow) which returns null on allocation failure. the copy can still fail and throw an exception!

C doesn't have exceptions and in general we should catch exceptions and translate them to error codes or let nothrow new do that for us.

@ZXShady ZXShady changed the title use non-throwing new operator to allocate memory for sfObj_create sfObj_copy use non-throwing new operator to allocate memory for sfObj_create / sfObj_copy Sep 17, 2024
@ChrisThrasher ChrisThrasher added this to the 3.0 milestone Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants