From 12bc1175f84f474dd0ea5f2df1dd082a41734773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Nordstro=CC=88m?= Date: Tue, 26 Jun 2018 11:06:39 +0200 Subject: [PATCH] Fix static analyzer warning when checking for index attributes This fixes a static analyzer warning about using an unititalized pointer. The analyzer doesn't realize that elog() will generate an exception, so that the unitialized NULL check will never occur. This change will clarify the code and silence the static analyzer. --- src/indexing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/indexing.c b/src/indexing.c index d141e99d7..66bd844ed 100644 --- a/src/indexing.c +++ b/src/indexing.c @@ -23,7 +23,7 @@ index_has_attribute(List *indexelems, const char *attrname) foreach(lc, indexelems) { Node *node = lfirst(lc); - const char *colname; + const char *colname = NULL; /* * The type of the element varies depending on whether the list is @@ -53,7 +53,7 @@ index_has_attribute(List *indexelems, const char *attrname) elog(ERROR, "unsupported index list element"); } - if (strncmp(colname, attrname, NAMEDATALEN) == 0) + if (colname != NULL && strncmp(colname, attrname, NAMEDATALEN) == 0) return true; }