From d770acde179d2cb2a9318f36405433737065169a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 4 Dec 2018 11:09:04 +0100
Subject: [PATCH] lib: fix coverity warnings
Resolves:
https://github.com/pbrezina/authselect/issues/126
---
src/lib/authselect.c | 2 +-
src/lib/util/string.c | 2 ++
src/lib/util/string_array.c | 2 +-
src/lib/util/template.c | 4 ++--
4 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/lib/authselect.c b/src/lib/authselect.c
index 0f8d4a8b6d0b0faef81daf176486108ed0ea74db..ce34d2a44d1a59cb574331733929d551c5aec075 100644
--- a/src/lib/authselect.c
+++ b/src/lib/authselect.c
@@ -146,9 +146,9 @@ _PUBLIC_ int
authselect_apply_changes(void)
{
struct authselect_profile *profile;
+ char **supported = NULL;
char *profile_id;
char **features;
- char **supported;
errno_t ret;
int i;
diff --git a/src/lib/util/string.c b/src/lib/util/string.c
index e6803bcd4e41adc05eaa623089009b17ccd4f49b..0f3936681c6c8af1be940f92a21dfc15dafe4e42 100644
--- a/src/lib/util/string.c
+++ b/src/lib/util/string.c
@@ -353,6 +353,8 @@ string_levenshtein(const char *a, const char *b)
unsigned int old_diag;
unsigned int column[len_a + 1];
+ memset(column, 0, (len_a + 1) * sizeof(unsigned int));
+
for (y = 1; y <= len_a; y++) {
column[y] = y;
}
diff --git a/src/lib/util/string_array.c b/src/lib/util/string_array.c
index e8871dc067fbf3d461d1ee9579813ddc81eef676..dcf667e2e6e0c918a0c4eacad2486fdc182d8cf6 100644
--- a/src/lib/util/string_array.c
+++ b/src/lib/util/string_array.c
@@ -228,7 +228,7 @@ string_array_find_similar(const char *value, char **array, int max_distance)
}
}
- if (best > max_distance) {
+ if (word == NULL || best > max_distance) {
return NULL;
}
diff --git a/src/lib/util/template.c b/src/lib/util/template.c
index fb373c0fd83e04c6c78d5f57d3d8e50e54c0377b..0eedd2b04146f201a5c37f45c1d08f01c079d61f 100644
--- a/src/lib/util/template.c
+++ b/src/lib/util/template.c
@@ -130,8 +130,8 @@ template_match_get_values(const char *match_string,
char **_if_true,
char **_if_false)
{
- regmatch_t *m_true;
- regmatch_t *m_false;
+ regmatch_t *m_true = NULL;
+ regmatch_t *m_false = NULL;
char *if_true;
char *if_false;
--
2.17.2