From f28e45f2f67504204d6eb24e4f5343dae8e9edd3 Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Thu, 12 Sep 2024 22:14:08 +0200 Subject: [PATCH] Add basic error handling --- profiler/src/ini.c | 3 ++- server/TracyPrint.hpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/profiler/src/ini.c b/profiler/src/ini.c index ab5f11d75e..f84b1fe265 100644 --- a/profiler/src/ini.c +++ b/profiler/src/ini.c @@ -193,7 +193,8 @@ ini_t* ini_load(const char *filename) { /* Get file size */ fseek(fp, 0, SEEK_END); - sz = ftell(fp); + const long file_size = ftell(fp); + sz = file_size > 0 ? file_size : 0; rewind(fp); /* Load file content into memory, null terminate, init end var */ diff --git a/server/TracyPrint.hpp b/server/TracyPrint.hpp index d38245e359..12db00965b 100644 --- a/server/TracyPrint.hpp +++ b/server/TracyPrint.hpp @@ -85,7 +85,8 @@ static inline char* PrintFloat( char* begin, char* end, T value, int precision ) #ifndef NO_CHARCONV return std::to_chars( begin, end, value, std::chars_format::fixed, precision ).ptr; #else - return begin + sprintf( begin, "%.*f", precision, value ); + auto length = sprintf( begin, "%.*f", precision, value ); + return length < 0 ? "" : begin + length; // TODO: Proper error handling for negative length #endif } @@ -95,7 +96,8 @@ static inline char* PrintFloat( char* begin, char* end, T value ) #ifndef NO_CHARCONV return std::to_chars( begin, end, value, std::chars_format::fixed ).ptr; #else - return begin + sprintf( begin, "%f", value ); + auto length = sprintf( begin, "%f", value ); + return length < 0 ? "" : begin + length; // TODO: Proper error handling for negative length #endif }