From 93b7b5a8e79e0dcffeb818e82e51f4146606385c Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 3 Jun 2020 11:11:15 -0700 Subject: [PATCH 1/2] ensure regs is initialized even if cpuid fails --- client/TracyProfiler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 1fae4fed..105411a5 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -173,6 +173,7 @@ struct ThreadHandleWrapper #if defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 static inline void CpuId( uint32_t* regs, uint32_t leaf ) { + memset(regs, 0, sizeof(uint32_t) * 4); #if defined _WIN32 || defined __CYGWIN__ __cpuidex( (int*)regs, leaf, 0 ); #else From 28a29d071f2c699cc75883acba5924fc91d6eaf4 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 3 Jun 2020 11:11:47 -0700 Subject: [PATCH 2/2] only write SysTime::used if fscanf succeeds --- client/TracySysTime.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/TracySysTime.cpp b/client/TracySysTime.cpp index 2a937bc4..e5903467 100644 --- a/client/TracySysTime.cpp +++ b/client/TracySysTime.cpp @@ -47,9 +47,12 @@ void SysTime::ReadTimes() FILE* f = fopen( "/proc/stat", "r" ); if( f ) { - fscanf( f, "cpu %" PRIu64 " %" PRIu64 " %" PRIu64" %" PRIu64, &user, &nice, &system, &idle ); + int read = fscanf( f, "cpu %" PRIu64 " %" PRIu64 " %" PRIu64" %" PRIu64, &user, &nice, &system, &idle ); fclose( f ); - used = user + nice + system; + if (read == 4) + { + used = user + nice + system; + } } }