Skip to content

Commit

Permalink
Fix clang warnings for vsprintf() and type mismatches on non-windows …
Browse files Browse the repository at this point in the history
…64-bit platforms
  • Loading branch information
SRSaunders committed Feb 17, 2024
1 parent 8e77240 commit 3ecf0ae
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/optick.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,8 @@ struct OPTICK_API EventDescription
uint32_t filter;
uint8_t flags;

static EventDescription* Create(const char* eventName, const char* fileName, const unsigned long fileLine, const unsigned long eventColor = Color::Null, const unsigned long filter = 0, const uint8_t eventFlags = 0);
static EventDescription* CreateShared(const char* eventName, const char* fileName = nullptr, const unsigned long fileLine = 0, const unsigned long eventColor = Color::Null, const unsigned long filter = 0);
static EventDescription* Create(const char* eventName, const char* fileName, const uint32_t fileLine, const uint32_t eventColor = Color::Null, const uint32_t filter = 0, const uint8_t eventFlags = 0);
static EventDescription* CreateShared(const char* eventName, const char* fileName = nullptr, const uint32_t fileLine = 0, const uint32_t eventColor = Color::Null, const uint32_t filter = 0);

EventDescription();
private:
Expand Down Expand Up @@ -700,11 +700,11 @@ OPTICK_INLINE Optick::EventDescription* CreateDescription(const char* functionNa
if (eventName != nullptr)
flags |= ::Optick::EventDescription::IS_CUSTOM_NAME;

return ::Optick::EventDescription::Create(eventName != nullptr ? eventName : functionName, fileName, (unsigned long)fileLine, ::Optick::Category::GetColor(category), ::Optick::Category::GetMask(category), flags);
return ::Optick::EventDescription::Create(eventName != nullptr ? eventName : functionName, fileName, (uint32_t)fileLine, ::Optick::Category::GetColor(category), ::Optick::Category::GetMask(category), flags);
}
OPTICK_INLINE Optick::EventDescription* CreateDescription(const char* functionName, const char* fileName, int fileLine, const ::Optick::Category::Type category)
{
return ::Optick::EventDescription::Create(functionName, fileName, (unsigned long)fileLine, ::Optick::Category::GetColor(category), ::Optick::Category::GetMask(category));
return ::Optick::EventDescription::Create(functionName, fileName, (uint32_t)fileLine, ::Optick::Category::GetColor(category), ::Optick::Category::GetMask(category));
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct OPTICK_API GPUEvent
Expand Down
4 changes: 2 additions & 2 deletions src/optick_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ inline int sprintf_s(char(&buffer)[sizeOfBuffer], const char* format, ...)
#if defined(OPTICK_GCC)
#include <string.h>
template<size_t sizeOfBuffer>
inline int wcstombs_s(char(&buffer)[sizeOfBuffer], const wchar_t* src, size_t maxCount)
inline size_t wcstombs_s(char(&buffer)[sizeOfBuffer], const wchar_t* src, size_t maxCount)
{
return wcstombs(buffer, src, maxCount);
}
#endif

#if defined(OPTICK_MSVC)
template<size_t sizeOfBuffer>
inline int wcstombs_s(char(&buffer)[sizeOfBuffer], const wchar_t* src, size_t maxCount)
inline size_t wcstombs_s(char(&buffer)[sizeOfBuffer], const wchar_t* src, size_t maxCount)
{
size_t converted = 0;
return ::wcstombs_s(&converted, buffer, src, maxCount);
Expand Down
7 changes: 4 additions & 3 deletions src/optick_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ void SortMemoryPool(MemoryPool<T, SIZE>& memoryPool)
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EventDescription* EventDescription::Create(const char* eventName, const char* fileName, const unsigned long fileLine, const unsigned long eventColor /*= Color::Null*/, const unsigned long filter /*= 0*/, const uint8_t eventFlags /*= 0*/)
EventDescription* EventDescription::Create(const char* eventName, const char* fileName, const uint32_t fileLine, const uint32_t eventColor /*= Color::Null*/, const uint32_t filter /*= 0*/, const uint8_t eventFlags /*= 0*/)
{
return EventDescriptionBoard::Get().CreateDescription(eventName, fileName, fileLine, eventColor, filter, eventFlags);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EventDescription* EventDescription::CreateShared(const char* eventName, const char* fileName, const unsigned long fileLine, const unsigned long eventColor /*= Color::Null*/, const unsigned long filter /*= 0*/)
EventDescription* EventDescription::CreateShared(const char* eventName, const char* fileName, const uint32_t fileLine, const uint32_t eventColor /*= Color::Null*/, const uint32_t filter /*= 0*/)
{
return EventDescriptionBoard::Get().CreateSharedDescription(eventName, fileName, fileLine, eventColor, filter);
}
Expand Down Expand Up @@ -840,7 +840,8 @@ void Core::DumpProgressFormatted(const char* format, ...)
#ifdef OPTICK_MSVC
vsprintf_s(buffer, format, arglist);
#else
vsprintf(buffer, format, arglist);
// SRS - use vsnprintf() for buffer security and to eliminate warning
vsnprintf(buffer, sizeof(buffer), format, arglist);
#endif
va_end(arglist);
DumpProgress(buffer);
Expand Down
4 changes: 2 additions & 2 deletions src/optick_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class Socket
return true;
}

int Receive(char *buf, int len)
ssize_t Receive(char *buf, int len)
{
std::lock_guard<std::recursive_mutex> lock(socketLock);

Expand Down Expand Up @@ -304,7 +304,7 @@ void Server::Update()
if (!InitConnection())
return;

int length = -1;
ssize_t length = -1;
while ( (length = socket->Receive( buffer, BIFFER_SIZE ) ) > 0 )
{
networkStream.Append(buffer, length);
Expand Down

0 comments on commit 3ecf0ae

Please sign in to comment.