Skip to content

Commit 282ca78

Browse files
committed
Add basic error handling
1 parent 55da9d1 commit 282ca78

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

profiler/src/ini.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ ini_t* ini_load(const char *filename) {
193193

194194
/* Get file size */
195195
fseek(fp, 0, SEEK_END);
196-
sz = ftell(fp);
196+
const long file_size = ftell(fp);
197+
sz = file_size > 0 ? file_size : 0;
197198
rewind(fp);
198199

199200
/* Load file content into memory, null terminate, init end var */

server/TracyPrint.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ static inline char* PrintFloat( char* begin, char* end, T value, int precision )
8585
#ifndef NO_CHARCONV
8686
return std::to_chars( begin, end, value, std::chars_format::fixed, precision ).ptr;
8787
#else
88-
return begin + sprintf( begin, "%.*f", precision, value );
88+
auto end_index = sprintf( begin, "%.*f", precision, value );
89+
return end_index < begin ? "" : begin + end_index; // TODO: Proper error handling for end index less than beginning
8990
#endif
9091
}
9192

@@ -95,7 +96,8 @@ static inline char* PrintFloat( char* begin, char* end, T value )
9596
#ifndef NO_CHARCONV
9697
return std::to_chars( begin, end, value, std::chars_format::fixed ).ptr;
9798
#else
98-
return begin + sprintf( begin, "%f", value );
99+
auto end_index = sprintf( begin, "%f", value );
100+
return end_index < begin ? "" : begin + end_index; // TODO: Proper error handling for end index less than beginning
99101
#endif
100102
}
101103

0 commit comments

Comments
 (0)