From 868f4eef3deb3cfa3c632cb6661f16d126f5f561 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 5 Aug 2023 08:31:46 -0700 Subject: [PATCH] Various cleanups (#1099) * cmake: remove atomic checks All this stuff was replaced with std::atomic Fixes: 9bcba812af0ba36df63210415321877f2204c629 Signed-off-by: Rosen Penev * cmake: remove vsnprintf checks Available since C++11 Signed-off-by: Rosen Penev * clang-tidy: const ref conversions Signed-off-by: Rosen Penev * clang-tidy: handle self assignment Found with bugprone-unhandled-self-assignment,cert-oop54-cpp Signed-off-by: Rosen Penev * clang-tidy: remove wrong forward declarations Found with bugprone-forward-declaration-namespace Signed-off-by: Rosen Penev --------- Signed-off-by: Rosen Penev --- ConfigureChecks.cmake | 73 ------------------- config.h.cmake | 10 --- taglib/flac/flacproperties.h | 2 - taglib/mp4/mp4atom.h | 3 +- .../id3v2/frames/synchronizedlyricsframe.h | 3 +- taglib/mpeg/id3v2/id3v2tag.h | 1 - taglib/toolkit/tmap.tcc | 3 + taglib/toolkit/tutils.h | 20 +---- 8 files changed, 8 insertions(+), 107 deletions(-) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 29e015d8..edd1845a 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -34,53 +34,6 @@ if(NOT ${SIZEOF_DOUBLE} EQUAL 8) message(FATAL_ERROR "TagLib requires that double is 64-bit wide.") endif() -# Determine which kind of atomic operations your compiler supports. - -check_cxx_source_compiles(" - int main() { - volatile int x; - __sync_add_and_fetch(&x, 1); - int y = __sync_sub_and_fetch(&x, 1); - return 0; - } - " HAVE_GCC_ATOMIC) - -if(NOT HAVE_GCC_ATOMIC) - check_cxx_source_compiles(" - #include - int main() { - volatile int32_t x; - OSAtomicIncrement32Barrier(&x); - int32_t y = OSAtomicDecrement32Barrier(&x); - return 0; - } - " HAVE_MAC_ATOMIC) - - if(NOT HAVE_MAC_ATOMIC) - check_cxx_source_compiles(" - #include - int main() { - volatile LONG x; - InterlockedIncrement(&x); - LONG y = InterlockedDecrement(&x); - return 0; - } - " HAVE_WIN_ATOMIC) - - if(NOT HAVE_WIN_ATOMIC) - check_cxx_source_compiles(" - #include - int main() { - volatile int x; - __sync_add_and_fetch(&x, 1); - int y = __sync_sub_and_fetch(&x, 1); - return 0; - } - " HAVE_IA64_ATOMIC) - endif() - endif() -endif() - # Determine which kind of byte swap functions your compiler supports. check_cxx_source_compiles(" @@ -140,32 +93,6 @@ if(NOT HAVE_GCC_BYTESWAP) endif() endif() -# Determine whether your compiler supports some safer version of vsprintf. - -check_cxx_source_compiles(" - #include - #include - int main() { - char buf[20]; - va_list args; - vsnprintf(buf, 20, \"%d\", args); - return 0; - } -" HAVE_VSNPRINTF) - -if(NOT HAVE_VSNPRINTF) - check_cxx_source_compiles(" - #include - #include - int main() { - char buf[20]; - va_list args; - vsprintf_s(buf, \"%d\", args); - return 0; - } - " HAVE_VSPRINTF_S) -endif() - # Determine whether your compiler supports ISO _strdup. check_cxx_source_compiles(" diff --git a/config.h.cmake b/config.h.cmake index 8d8c36ab..67334d79 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -10,16 +10,6 @@ #cmakedefine HAVE_MAC_BYTESWAP 1 #cmakedefine HAVE_OPENBSD_BYTESWAP 1 -/* Defined if your compiler supports some atomic operations */ -#cmakedefine HAVE_GCC_ATOMIC 1 -#cmakedefine HAVE_MAC_ATOMIC 1 -#cmakedefine HAVE_WIN_ATOMIC 1 -#cmakedefine HAVE_IA64_ATOMIC 1 - -/* Defined if your compiler supports some safer version of vsprintf */ -#cmakedefine HAVE_VSNPRINTF 1 -#cmakedefine HAVE_VSPRINTF_S 1 - /* Defined if your compiler supports ISO _strdup */ #cmakedefine HAVE_ISO_STRDUP 1 diff --git a/taglib/flac/flacproperties.h b/taglib/flac/flacproperties.h index 1fe90c3f..db0c5c7d 100644 --- a/taglib/flac/flacproperties.h +++ b/taglib/flac/flacproperties.h @@ -34,8 +34,6 @@ namespace TagLib { namespace FLAC { - class File; - //! An implementation of audio property reading for FLAC /*! diff --git a/taglib/mp4/mp4atom.h b/taglib/mp4/mp4atom.h index 1578c0e8..cad81996 100644 --- a/taglib/mp4/mp4atom.h +++ b/taglib/mp4/mp4atom.h @@ -64,7 +64,8 @@ namespace TagLib { }; struct AtomData { - AtomData(AtomDataType type, ByteVector data) : type(type), locale(0), data(data) {} + AtomData(AtomDataType type, const ByteVector &data) : + type(type), locale(0), data(data) { } AtomDataType type; int locale; ByteVector data; diff --git a/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.h b/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.h index 96b71980..71d852db 100644 --- a/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.h +++ b/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.h @@ -85,7 +85,8 @@ namespace TagLib { * Single entry of time stamp and lyrics text. */ struct SynchedText { - SynchedText(unsigned int ms, String str) : time(ms), text(str) {} + SynchedText(unsigned int ms, const String &str) : + time(ms), text(str) { } unsigned int time; String text; }; diff --git a/taglib/mpeg/id3v2/id3v2tag.h b/taglib/mpeg/id3v2/id3v2tag.h index 4a2167b0..7bbc9f12 100644 --- a/taglib/mpeg/id3v2/id3v2tag.h +++ b/taglib/mpeg/id3v2/id3v2tag.h @@ -44,7 +44,6 @@ namespace TagLib { class Header; class ExtendedHeader; - class Footer; typedef List FrameList; typedef Map FrameListMap; diff --git a/taglib/toolkit/tmap.tcc b/taglib/toolkit/tmap.tcc index 1096086f..534894b5 100644 --- a/taglib/toolkit/tmap.tcc +++ b/taglib/toolkit/tmap.tcc @@ -189,6 +189,9 @@ T &Map::operator[](const Key &key) template Map &Map::operator=(const Map &m) { + if (this == &m) + return *this; + Map(m).swap(*this); return *this; } diff --git a/taglib/toolkit/tutils.h b/taglib/toolkit/tutils.h index 762358e5..8cd376dd 100644 --- a/taglib/toolkit/tutils.h +++ b/taglib/toolkit/tutils.h @@ -179,25 +179,7 @@ namespace TagLib char buf[BufferSize]; int length; -#if defined(HAVE_VSNPRINTF) - - length = vsnprintf(buf, BufferSize, format, args); - -#elif defined(HAVE_VSPRINTF_S) - - length = vsprintf_s(buf, format, args); - -#else - - // The last resort. May cause a buffer overflow. - - length = vsprintf(buf, format, args); - if(length >= BufferSize) { - debug("Utils::formatString() - Buffer overflow! Returning an empty string."); - length = -1; - } - -#endif + length = std::vsnprintf(buf, BufferSize, format, args); va_end(args);