diff --git a/libobs/util/config-file.c b/libobs/util/config-file.c index 8040c5045aa935ec7be21f9d22a32ebee006be53..d0c61513722ae66304a23917e101acbcb91b9cb7 100644 --- a/libobs/util/config-file.c +++ b/libobs/util/config-file.c @@ -405,9 +405,15 @@ int config_save(config_t *config) } #ifdef _WIN32 - fwrite("\xEF\xBB\xBF", 1, 3, f); + if (fwrite("\xEF\xBB\xBF", 3, 1, f) != 1) { + fclose(f); + return CONFIG_ERROR; + } #endif - fwrite(str.array, 1, str.len, f); + if (fwrite(str.array, str.len, 1, f) != 1) { + fclose(f); + return CONFIG_ERROR; + } fclose(f); pthread_mutex_unlock(&config->mutex); @@ -444,6 +450,8 @@ int config_save_safe(config_t *config, const char *temp_ext, config->file = file; if (ret != CONFIG_SUCCESS) { + blog(LOG_ERROR, "config_save_safe: failed to " + "write to %s", temp_file.array); goto cleanup; } diff --git a/libobs/util/platform.c b/libobs/util/platform.c index 6826ea4ef4b4e385d499c22f6b88bfe27f2140a6..a8d036e419ad4af70b84958daa43dfcc69084d8e 100644 --- a/libobs/util/platform.c +++ b/libobs/util/platform.c @@ -262,10 +262,19 @@ bool os_quick_write_utf8_file(const char *path, const char *str, size_t len, if (!f) return false; - if (marker) - fwrite("\xEF\xBB\xBF", 1, 3, f); - if (len) - fwrite(str, 1, len, f); + if (marker) { + if (fwrite("\xEF\xBB\xBF", 3, 1, f) != 1) { + fclose(f); + return false; + } + } + + if (len) { + if (fwrite(str, len, 1, f) != 1) { + fclose(f); + return false; + } + } fflush(f); fclose(f); @@ -292,6 +301,8 @@ bool os_quick_write_utf8_file_safe(const char *path, const char *str, dstr_cat(&temp_path, temp_ext); if (!os_quick_write_utf8_file(temp_path.array, str, len, marker)) { + blog(LOG_ERROR, "os_quick_write_utf8_file_safe: failed to " + "write to %s", temp_path.array); goto cleanup; }