Skip to content

Commit

Permalink
Assert that filepath strings are not null
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Sep 16, 2024
1 parent 9765e30 commit 21d4571
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/CSFML/Audio/Music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
////////////////////////////////////////////////////////////
sfMusic* sfMusic_createFromFile(const char* filename)
{
assert(filename);

auto* music = new sfMusic;
if (!music->This.openFromFile(filename))
{
Expand Down
3 changes: 3 additions & 0 deletions src/CSFML/Audio/SoundBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_createFromFile(const char* filename)
{
assert(filename);

sf::SoundBuffer soundBuffer;
if (!soundBuffer.loadFromFile(filename))
return nullptr;
Expand Down Expand Up @@ -106,6 +108,7 @@ void sfSoundBuffer_destroy(const sfSoundBuffer* soundBuffer)
bool sfSoundBuffer_saveToFile(const sfSoundBuffer* soundBuffer, const char* filename)
{
assert(soundBuffer);
assert(filename);
return soundBuffer->This.saveToFile(filename);
}

Expand Down
2 changes: 2 additions & 0 deletions src/CSFML/Graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
////////////////////////////////////////////////////////////
sfFont* sfFont_createFromFile(const char* filename)
{
assert(filename);

sf::Font font;
if (!font.openFromFile(filename))
return nullptr;
Expand Down
3 changes: 3 additions & 0 deletions src/CSFML/Graphics/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ sfImage* sfImage_createFromPixels(sfVector2u size, const uint8_t* data)
////////////////////////////////////////////////////////////
sfImage* sfImage_createFromFile(const char* filename)
{
assert(filename);

sf::Image image;
if (!image.loadFromFile(filename))
return nullptr;
Expand Down Expand Up @@ -110,6 +112,7 @@ void sfImage_destroy(const sfImage* image)
bool sfImage_saveToFile(const sfImage* image, const char* filename)
{
assert(image);
assert(filename);
return image->This.saveToFile(filename);
}

Expand Down
4 changes: 4 additions & 0 deletions src/CSFML/Graphics/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ sfTexture* sfTexture_create(sfVector2u size)
////////////////////////////////////////////////////////////
sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area)
{
assert(filename);

auto* texture = new sfTexture;

const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
Expand All @@ -69,6 +71,8 @@ sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area)
////////////////////////////////////////////////////////////
sfTexture* sfTexture_createSrgbFromFile(const char* filename, const sfIntRect* area)
{
assert(filename);

auto* texture = new sfTexture;

const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
Expand Down

0 comments on commit 21d4571

Please sign in to comment.