dont use format string if an error occures

This commit is contained in:
Linus Dierheimer
2021-04-03 21:51:50 +02:00
parent 67465d266e
commit e01d03f98d
13 changed files with 198 additions and 152 deletions
+13 -7
View File
@@ -5,6 +5,17 @@ void ffPrintOS(FFinstance* instance)
if(ffPrintCachedValue(instance, &instance->config.osKey, "OS"))
return;
FILE* osRelease = fopen("/etc/os-release", "r");
if(osRelease == NULL)
osRelease = fopen("/usr/lib/os-release", "r");
if(osRelease == NULL)
{
ffPrintError(instance, &instance->config.osKey, "OS", "couldn't read /etc/os-release nor /usr/lib/os-release");
return;
}
// Documentation of the fields:
// https://www.freedesktop.org/software/systemd/man/os-release.html
@@ -19,11 +30,6 @@ void ffPrintOS(FFinstance* instance)
char versionCodename[128]; versionCodename[0] = '\0';
char buildId[128]; buildId[0] = '\0';
FILE* osRelease = fopen("/etc/os-release", "r");
if(osRelease == NULL)
osRelease = fopen("/usr/lib/os-release", "r");
char* line = NULL;
size_t len = 0;
@@ -51,11 +57,11 @@ void ffPrintOS(FFinstance* instance)
sscanf(line, "BUILD_ID=\"%[^\"]+", buildId);
}
fclose(osRelease);
if(line != NULL)
free(line);
fclose(osRelease);
FF_STRBUF_CREATE(os);
if(instance->config.osFormat.length == 0)