Skip to content

Commit

Permalink
Add basic error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tygyh committed Sep 12, 2024
1 parent 55da9d1 commit 282ca78
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion profiler/src/ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 4 additions & 2 deletions server/TracyPrint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 end_index = sprintf( begin, "%.*f", precision, value );
return end_index < begin ? "" : begin + end_index; // TODO: Proper error handling for end index less than beginning
#endif
}

Expand All @@ -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 end_index = sprintf( begin, "%f", value );
return end_index < begin ? "" : begin + end_index; // TODO: Proper error handling for end index less than beginning
#endif
}

Expand Down

0 comments on commit 282ca78

Please sign in to comment.