Author: sagamusix
Date: Sun Jun 2 22:44:18 2024
New Revision: 20923
URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20923
Log:
[Imp] In tracker debug builds, verify that for successfully loaded files the result of the corresponding probing function is successful, too. This makes it easier to verify the API contract outside of libopenmpt builds.
Modified:
trunk/OpenMPT/soundlib/Sndfile.cpp
Modified: trunk/OpenMPT/soundlib/Sndfile.cpp
==============================================================================
--- trunk/OpenMPT/soundlib/Sndfile.cpp Sun Jun 2 20:30:15 2024 (r20922)
+++ trunk/OpenMPT/soundlib/Sndfile.cpp Sun Jun 2 22:44:18 2024 (r20923)
@@ -244,7 +244,7 @@
decltype(&CSoundFile::ReadXM) loader;
};
-#ifdef MODPLUG_TRACKER
+#if defined(MODPLUG_TRACKER) && !defined(MPT_BUILD_DEBUG)
#define MPT_DECLARE_FORMAT(format) { nullptr, &CSoundFile::Read ## format }
#else
#define MPT_DECLARE_FORMAT(format) { CSoundFile::ProbeFileHeader ## format, &CSoundFile::Read ## format }
@@ -507,7 +507,17 @@
{
loaderSuccess = (this->*(format.loader))(file, loadFlags);
if(loaderSuccess)
+ {
+#if defined(MPT_BUILD_DEBUG)
+ // Verify that the probing function is consistent with our API contract
+ file.Rewind();
+ const auto data = file.GetRawDataAsByteVector(ProbeRecommendedSize);
+ MemoryFileReader mf{mpt::as_span(data)};
+ const uint64 size = file.GetLength();
+ MPT_ASSERT(format.prober(mf, &size) != ProbeFailure);
+#endif
break;
+ }
}
if(!loaderSuccess)
|