Browse Source

Some static analysis fixes

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
021da72077

+ 4 - 5
AnKi/Core/CoreTracer.cpp

@@ -6,8 +6,8 @@
 #include <AnKi/Core/CoreTracer.h>
 #include <AnKi/Util/DynamicArray.h>
 #include <AnKi/Util/Tracer.h>
+#include <AnKi/Util/System.h>
 #include <AnKi/Math/Functions.h>
-#include <ctime>
 
 namespace anki
 {
@@ -118,11 +118,10 @@ Error CoreTracer::init(GenericMemoryPoolAllocator<U8> alloc, CString directory)
 		return static_cast<CoreTracer*>(info.m_userData)->threadWorker();
 	});
 
-	std::time_t t = std::time(nullptr);
-	std::tm* tm = std::localtime(&t);
+	std::tm tm = getLocalTime();
 	StringAuto fname(m_alloc);
-	fname.sprintf("%s/%d%02d%02d-%02d%02d_", directory.cstr(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
-				  tm->tm_hour, tm->tm_min);
+	fname.sprintf("%s/%d%02d%02d-%02d%02d_", directory.cstr(), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
+				  tm.tm_min);
 
 	ANKI_CHECK(m_traceJsonFile.open(StringAuto(alloc).sprintf("%strace.json", fname.cstr()), FileOpenFlag::WRITE));
 	ANKI_CHECK(m_traceJsonFile.writeText("[\n"));

+ 6 - 0
AnKi/Gr/Common.h

@@ -228,6 +228,8 @@ public:
 	{
 	}
 
+	TextureSurfaceInfo& operator=(const TextureSurfaceInfo&) = default;
+
 	Bool operator==(const TextureSurfaceInfo& b) const
 	{
 		return m_level == b.m_level && m_depth == b.m_depth && m_face == b.m_face && m_layer == b.m_layer;
@@ -263,6 +265,8 @@ public:
 		: m_level(level)
 	{
 	}
+
+	TextureVolumeInfo& operator=(const TextureVolumeInfo&) = default;
 };
 
 /// Defines a subset of a texture.
@@ -311,6 +315,8 @@ public:
 	{
 	}
 
+	TextureSubresourceInfo& operator=(const TextureSubresourceInfo&) = default;
+
 	Bool operator==(const TextureSubresourceInfo& b) const
 	{
 		ANKI_ASSERT(_m_padding[0] == b._m_padding[0]);

+ 2 - 1
AnKi/Gr/RenderGraph.cpp

@@ -1318,9 +1318,10 @@ void RenderGraph::flush()
 
 	for(U32 i = 0; i < m_ctx->m_graphicsCmdbs.getSize(); ++i)
 	{
-		// Maybe write a timestamp before flush
 		if(ANKI_UNLIKELY(m_ctx->m_gatherStatistics && i == m_ctx->m_graphicsCmdbs.getSize() - 1))
 		{
+			// Write a timestamp before the last flush
+
 			TimestampQueryPtr query = getManager().newTimestampQuery();
 			m_ctx->m_graphicsCmdbs[i]->resetTimestampQuery(query);
 			m_ctx->m_graphicsCmdbs[i]->writeTimestamp(query);

+ 3 - 2
AnKi/Gr/Vulkan/CommandBufferImpl.inl.h

@@ -382,10 +382,11 @@ inline void CommandBufferImpl::dispatchCompute(U32 groupCountX, U32 groupCountY,
 	getGrManagerImpl().endMarker(m_handle);
 }
 
-inline void CommandBufferImpl::traceRaysInternal(BufferPtr& sbtBuffer, PtrSize sbtBufferOffset, U32 sbtRecordSize,
+inline void CommandBufferImpl::traceRaysInternal(BufferPtr& sbtBuffer, PtrSize sbtBufferOffset, U32 sbtRecordSize32,
 												 U32 hitGroupSbtRecordCount, U32 rayTypeCount, U32 width, U32 height,
 												 U32 depth)
 {
+	const PtrSize sbtRecordSize = sbtRecordSize32;
 	ANKI_ASSERT(hitGroupSbtRecordCount > 0);
 	ANKI_ASSERT(width > 0 && height > 0 && depth > 0);
 	ANKI_ASSERT(m_rtProg);
@@ -395,7 +396,7 @@ inline void CommandBufferImpl::traceRaysInternal(BufferPtr& sbtBuffer, PtrSize s
 
 	ANKI_ASSERT(rayTypeCount == sprog.getMissShaderCount() && "All the miss shaders should be in use");
 	ANKI_ASSERT((hitGroupSbtRecordCount % rayTypeCount) == 0);
-	const U32 sbtRecordCount = 1 + rayTypeCount + hitGroupSbtRecordCount;
+	const PtrSize sbtRecordCount = 1 + rayTypeCount + hitGroupSbtRecordCount;
 	const PtrSize sbtBufferSize = sbtRecordCount * sbtRecordSize;
 	(void)sbtBufferSize;
 	ANKI_ASSERT(sbtBufferSize + sbtBufferOffset <= sbtBuffer->getSize());

+ 1 - 1
AnKi/Renderer/DepthDownscale.cpp

@@ -57,7 +57,7 @@ Error DepthDownscale::initInternal(const ConfigSet&)
 		// Create buffer
 		BufferInitInfo buffInit("HiZ Client");
 		buffInit.m_mapAccess = BufferMapAccessBit::READ;
-		buffInit.m_size = lastMipHeight * lastMipWidth * sizeof(F32);
+		buffInit.m_size = PtrSize(lastMipHeight) * PtrSize(lastMipWidth) * sizeof(F32);
 		buffInit.m_usage = BufferUsageBit::STORAGE_COMPUTE_WRITE;
 		m_copyToBuff.m_buff = getGrManager().newBuffer(buffInit);
 

+ 1 - 1
AnKi/Renderer/RtShadows.cpp

@@ -288,7 +288,7 @@ void RtShadows::buildSbt()
 
 	// Allocate SBT
 	StagingGpuMemoryToken token;
-	U8* sbt = allocateStorage<U8*>(m_sbtRecordSize * (instanceCount + extraSbtRecords), token);
+	U8* sbt = allocateStorage<U8*>(PtrSize(m_sbtRecordSize) * (instanceCount + extraSbtRecords), token);
 	const U8* sbtStart = sbt;
 	(void)sbtStart;
 	m_runCtx.m_sbtBuffer = token.m_buffer;

+ 3 - 1
AnKi/Resource/ImageLoader.cpp

@@ -44,9 +44,11 @@ public:
 static_assert(sizeof(AnkiTextureHeader) == 128, "Check sizeof AnkiTextureHeader");
 
 /// Get the size in bytes of a single surface
-static PtrSize calcSurfaceSize(const U32 width, const U32 height, const ImageLoaderDataCompression comp,
+static PtrSize calcSurfaceSize(const U32 width32, const U32 height32, const ImageLoaderDataCompression comp,
 							   const ImageLoaderColorFormat cf)
 {
+	const PtrSize width = width32;
+	const PtrSize height = height32;
 	PtrSize out = 0;
 
 	ANKI_ASSERT(width >= 4 || height >= 4);

+ 1 - 1
AnKi/Ui/Font.cpp

@@ -71,7 +71,7 @@ void Font::createTexture(const void* data, U32 width, U32 height)
 	ANKI_ASSERT(data && width > 0 && height > 0);
 
 	// Create and populate the buffer
-	PtrSize buffSize = width * height * 4;
+	const U32 buffSize = width * height * 4;
 	BufferPtr buff = m_manager->getGrManager().newBuffer(
 		BufferInitInfo(buffSize, BufferUsageBit::TRANSFER_SOURCE, BufferMapAccessBit::WRITE, "UI"));
 	void* mapped = buff->map(0, buffSize, BufferMapAccessBit::WRITE);

+ 2 - 1
AnKi/Util/FilesystemPosix.cpp

@@ -218,7 +218,8 @@ Error getFileModificationTime(CString filename, U32& year, U32& month, U32& day,
 		return Error::NONE;
 	}
 
-	const struct tm& t = *localtime(&buff.st_mtim.tv_sec);
+	struct tm t;
+	localtime_r(&buff.st_mtim.tv_sec, &t);
 	year = 1900 + t.tm_year;
 	month = t.tm_mon + 1;
 	day = t.tm_mday;

+ 16 - 0
AnKi/Util/System.cpp

@@ -77,4 +77,20 @@ Bool runningFromATerminal()
 #endif
 }
 
+std::tm getLocalTime()
+{
+	std::time_t t = std::time(nullptr);
+	std::tm tm;
+
+#if ANKI_POSIX
+	localtime_r(&t, &tm);
+#elif ANKI_OS_WINDOWS
+	localtime_s(&tm, &t);
+#else
+#	error See file
+#endif
+
+	return tm;
+}
+
 } // end namespace anki

+ 4 - 0
AnKi/Util/System.h

@@ -6,6 +6,7 @@
 #pragma once
 
 #include <AnKi/Util/StdTypes.h>
+#include <ctime>
 
 namespace anki
 {
@@ -31,6 +32,9 @@ void getBacktrace(BackTraceWalker& walker);
 
 /// Return true if the engine is running from a terminal emulator.
 Bool runningFromATerminal();
+
+/// Return the local time in a thread safe way.
+std::tm getLocalTime();
 /// @}
 
 } // end namespace anki