[vlc-commits] [Git][videolan/vlc][master] medialibrary: thumb: check fclose while saving
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Aug 9 13:49:09 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
f1d4ade9 by Alaric Senat at 2023-08-09T12:41:53+00:00
medialibrary: thumb: check fclose while saving
It should not be assumed that the thumbnail was saved properly when
`fclose` fails.
The RAII wrapper here does not improve readability or shorten the code.
Removing it also works around a GCC `-Wignored-attributes` warning that
was triggered due to `fclose` being tagged as `__nonnull((1))`:
```text
modules/misc/medialibrary/MetadataExtractor.cpp: In member function ‘virtual bool EmbeddedThumbnail::save(const std::string&)’:
modules/misc/medialibrary/MetadataExtractor.cpp:44:44: warning: ignoring attributes on template argument ‘int (*)(FILE*)’ [-Wignored-attributes]
44 | std::unique_ptr<FILE, decltype(&fclose)> f{ vlc_fopen( path.c_str(), "wb" ),
| ^
```
Co-authored-by: Alexandre Janniaux <ajanni at videolabs.io>
- - - - -
1 changed file:
- modules/misc/medialibrary/MetadataExtractor.cpp
Changes:
=====================================
modules/misc/medialibrary/MetadataExtractor.cpp
=====================================
@@ -41,11 +41,14 @@ EmbeddedThumbnail::~EmbeddedThumbnail()
bool EmbeddedThumbnail::save( const std::string& path )
{
- std::unique_ptr<FILE, decltype(&fclose)> f{ vlc_fopen( path.c_str(), "wb" ),
- &fclose };
+ FILE* f = vlc_fopen( path.c_str(), "wb" );
+
if ( f == nullptr )
return false;
- auto res = fwrite( m_attachment->p_data, m_attachment->i_data, 1, f.get() );
+ auto res = fwrite( m_attachment->p_data, m_attachment->i_data, 1, f );
+
+ if ( fclose( f ) != 0 )
+ return false;
return res == 1;
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/f1d4ade9bcd7a5ad05d910ad4d6dc58f012f39eb
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/f1d4ade9bcd7a5ad05d910ad4d6dc58f012f39eb
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list