resolved: avoid passing unitialized variable

The issue was introduced in the refactoring in 775ae35403.
We would pass an initialized value to a helper function. We would only *use*
it if it was initialized. But the mere passing of an unitialized variable is
UB, so let's not do that. This silences a gcc warning.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-04-01 11:12:57 +02:00
parent aff81b1851
commit e7d48709ed

View File

@@ -938,6 +938,8 @@ static int answer_add_clamp_ttl(
if (FLAGS_SET(query_flags, SD_RESOLVED_CLAMP_TTL)) {
uint32_t left_ttl;
assert(current > 0);
/* Let's determine how much time is left for this cache entry. Note that we round down, but
* clamp this to be 1s at minimum, since we usually want records to remain cached better too
* short a time than too long a time, but otoh don't want to return 0 ever, since that has
@@ -988,7 +990,7 @@ int dns_cache_lookup(
bool nxdomain = false;
DnsCacheItem *j, *first, *nsec = NULL;
bool have_authenticated = false, have_non_authenticated = false, have_confidential = false, have_non_confidential = false;
usec_t current;
usec_t current = 0;
int found_rcode = -1;
DnssecResult dnssec_result = -1;
int have_dnssec_result = -1;
@@ -1014,8 +1016,12 @@ int dns_cache_lookup(
goto miss;
}
if (FLAGS_SET(query_flags, SD_RESOLVED_CLAMP_TTL))
if (FLAGS_SET(query_flags, SD_RESOLVED_CLAMP_TTL)) {
/* 'current' is always passed to answer_add_clamp_ttl(), but is only used conditionally.
* We'll do the same assert there to make sure that it was initialized properly. */
current = now(clock_boottime_or_monotonic());
assert(current > 0);
}
LIST_FOREACH(by_key, j, first) {
/* If the caller doesn't allow us to answer questions from cache data learned from