Add basic error handling

This commit is contained in:
Dr. Dystopia 2024-09-12 22:14:08 +02:00
parent 55da9d1084
commit f28e45f2f6
2 changed files with 6 additions and 3 deletions

View File

@ -193,7 +193,8 @@ ini_t* ini_load(const char *filename) {
/* Get file size */ /* Get file size */
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
sz = ftell(fp); const long file_size = ftell(fp);
sz = file_size > 0 ? file_size : 0;
rewind(fp); rewind(fp);
/* Load file content into memory, null terminate, init end var */ /* Load file content into memory, null terminate, init end var */

View File

@ -85,7 +85,8 @@ static inline char* PrintFloat( char* begin, char* end, T value, int precision )
#ifndef NO_CHARCONV #ifndef NO_CHARCONV
return std::to_chars( begin, end, value, std::chars_format::fixed, precision ).ptr; return std::to_chars( begin, end, value, std::chars_format::fixed, precision ).ptr;
#else #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 #endif
} }
@ -95,7 +96,8 @@ static inline char* PrintFloat( char* begin, char* end, T value )
#ifndef NO_CHARCONV #ifndef NO_CHARCONV
return std::to_chars( begin, end, value, std::chars_format::fixed ).ptr; return std::to_chars( begin, end, value, std::chars_format::fixed ).ptr;
#else #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 #endif
} }