You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2017/05/09 21:29:33 UTC
[trafficserver] branch master updated: Coverity 1021705:
Uninitialized pointer field
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 2601e0e Coverity 1021705: Uninitialized pointer field
2601e0e is described below
commit 2601e0e202dff8dd9b7f1cf641b75514453ff820
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Tue May 9 14:16:53 2017 -0400
Coverity 1021705: Uninitialized pointer field
This also cleans up the Matcher class layout, such that we
cleanly initialize everything in one place.
---
iocore/cache/CacheHosting.cc | 9 +--
iocore/cache/P_CacheHosting.h | 12 ++--
proxy/ControlMatcher.cc | 35 ++--------
proxy/ControlMatcher.h | 154 +++++++++++++++++++++---------------------
4 files changed, 91 insertions(+), 119 deletions(-)
diff --git a/iocore/cache/CacheHosting.cc b/iocore/cache/CacheHosting.cc
index 5eb45b0..6952205 100644
--- a/iocore/cache/CacheHosting.cc
+++ b/iocore/cache/CacheHosting.cc
@@ -29,8 +29,6 @@
extern int gndisks;
-matcher_tags CacheHosting_tags = {"hostname", "domain", nullptr, nullptr, nullptr, nullptr, false};
-
/*************************************************************
* Begin class HostMatcher
*************************************************************/
@@ -184,14 +182,9 @@ CacheHostTable::CacheHostTable(Cache *c, CacheType typ)
{
ats_scoped_str config_path;
- config_tags = &CacheHosting_tags;
- ink_assert(config_tags != nullptr);
-
type = typ;
cache = c;
matcher_name = "[CacheHosting]";
- ;
- hostMatch = nullptr;
config_path = RecConfigReadConfigPath("proxy.config.cache.hosting_filename");
ink_release_assert(config_path);
@@ -284,7 +277,7 @@ CacheHostTable::BuildTableFromString(const char *config_file_path, char *file_bu
if (*tmp != '#' && *tmp != '\0') {
current = (matcher_line *)ats_malloc(sizeof(matcher_line));
- errPtr = parseConfigLine((char *)tmp, current, config_tags);
+ errPtr = parseConfigLine((char *)tmp, current, &config_tags);
if (errPtr != nullptr) {
RecSignalWarning(REC_SIGNAL_CONFIG_ERROR, "%s discarding %s entry at line %d : %s", matcher_name, config_file_path,
diff --git a/iocore/cache/P_CacheHosting.h b/iocore/cache/P_CacheHosting.h
index 7902682..cd85f6b 100644
--- a/iocore/cache/P_CacheHosting.h
+++ b/iocore/cache/P_CacheHosting.h
@@ -144,15 +144,15 @@ public:
REC_RegisterConfigUpdateFunc("proxy.config.cache.hosting_filename", CacheHostTable::config_callback, (void *)p);
}
- CacheType type;
- Cache *cache;
- int m_numEntries;
+ CacheType type = CACHE_HTTP_TYPE;
+ Cache *cache = nullptr;
+ int m_numEntries = 0;
CacheHostRecord gen_host_rec;
private:
- CacheHostMatcher *hostMatch;
- const matcher_tags *config_tags;
- const char *matcher_name; // Used for Debug/Warning/Error messages
+ CacheHostMatcher *hostMatch = nullptr;
+ const matcher_tags config_tags = {"hostname", "domain", nullptr, nullptr, nullptr, nullptr, false};
+ const char *matcher_name = "unknown"; // Used for Debug/Warning/Error messages
};
struct CacheHostTableConfig;
diff --git a/proxy/ControlMatcher.cc b/proxy/ControlMatcher.cc
index 7981bf0..5f290d6 100644
--- a/proxy/ControlMatcher.cc
+++ b/proxy/ControlMatcher.cc
@@ -88,8 +88,7 @@ HttpRequestData::get_client_ip()
*************************************************************/
template <class Data, class MatchResult>
-HostMatcher<Data, MatchResult>::HostMatcher(const char *name, const char *filename)
- : data_array(nullptr), array_len(-1), num_el(-1), matcher_name(name), file_name(filename)
+HostMatcher<Data, MatchResult>::HostMatcher(const char *name, const char *filename) : BaseMatcher<Data>(name, filename)
{
host_lookup = new HostLookup(name);
}
@@ -97,7 +96,6 @@ HostMatcher<Data, MatchResult>::HostMatcher(const char *name, const char *filena
template <class Data, class MatchResult> HostMatcher<Data, MatchResult>::~HostMatcher()
{
delete host_lookup;
- delete[] data_array;
}
//
@@ -142,9 +140,8 @@ HostMatcher<Data, MatchResult>::AllocateSpace(int num_entries)
host_lookup->AllocateSpace(num_entries);
data_array = new Data[num_entries];
-
- array_len = num_entries;
- num_el = 0;
+ array_len = num_entries;
+ num_el = 0;
}
// void HostMatcher<Data,MatchResult>::Match(RequestData* rdata, MatchResult* result)
@@ -237,15 +234,7 @@ HostMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
// UrlMatcher<Data,MatchResult>::UrlMatcher()
//
template <class Data, class MatchResult>
-UrlMatcher<Data, MatchResult>::UrlMatcher(const char *name, const char *filename)
- : url_ht(nullptr),
- url_str(nullptr),
- url_value(nullptr),
- data_array(nullptr),
- array_len(0),
- num_el(-1),
- matcher_name(name),
- file_name(filename)
+UrlMatcher<Data, MatchResult>::UrlMatcher(const char *name, const char *filename) : BaseMatcher<Data>(name, filename)
{
url_ht = ink_hash_table_create(InkHashTableKeyType_String);
}
@@ -261,7 +250,6 @@ template <class Data, class MatchResult> UrlMatcher<Data, MatchResult>::~UrlMatc
}
delete[] url_str;
delete[] url_value;
- delete[] data_array;
}
//
@@ -382,8 +370,7 @@ UrlMatcher<Data, MatchResult>::Match(RequestData *rdata, MatchResult *result)
// RegexMatcher<Data,MatchResult>::RegexMatcher()
//
template <class Data, class MatchResult>
-RegexMatcher<Data, MatchResult>::RegexMatcher(const char *name, const char *filename)
- : re_array(nullptr), re_str(nullptr), data_array(nullptr), array_len(-1), num_el(-1), matcher_name(name), file_name(filename)
+RegexMatcher<Data, MatchResult>::RegexMatcher(const char *name, const char *filename) : BaseMatcher<Data>(name, filename)
{
}
@@ -398,7 +385,6 @@ template <class Data, class MatchResult> RegexMatcher<Data, MatchResult>::~Regex
}
delete[] re_str;
ats_free(re_array);
- delete[] data_array;
}
//
@@ -589,17 +575,8 @@ HostRegexMatcher<Data, MatchResult>::Match(RequestData *rdata, MatchResult *resu
// IpMatcher<Data,MatchResult>::IpMatcher()
//
template <class Data, class MatchResult>
-IpMatcher<Data, MatchResult>::IpMatcher(const char *name, const char *filename)
- : data_array(nullptr), array_len(-1), num_el(-1), matcher_name(name), file_name(filename)
-{
-}
-
-//
-// IpMatcher<Data,MatchResult>::~IpMatcher()
-//
-template <class Data, class MatchResult> IpMatcher<Data, MatchResult>::~IpMatcher()
+IpMatcher<Data, MatchResult>::IpMatcher(const char *name, const char *filename) : BaseMatcher<Data>(name, filename)
{
- delete[] data_array;
}
//
diff --git a/proxy/ControlMatcher.h b/proxy/ControlMatcher.h
index b3f0f0d..3bc3f5c 100644
--- a/proxy/ControlMatcher.h
+++ b/proxy/ControlMatcher.h
@@ -166,9 +166,30 @@ public:
URL **cache_info_parent_selection_url;
};
-template <class Data, class MatchResult> class UrlMatcher
+// Mixin class for shared info across all templates. This just wraps the
+// shared members such that we don't have to duplicate all these initialixers
+// etc. If someone wants to rewrite all this code to use setters and getters,
+// by all means, please do so. The plumbing is in place :).
+template <class Data> class BaseMatcher
{
public:
+ BaseMatcher(const char *name, const char *filename) : matcher_name(name), file_name(filename) {}
+
+ ~BaseMatcher() { delete[] data_array; }
+
+protected:
+ int num_el = -1; // number of elements in the table
+ const char *matcher_name = "unknown"; // Used for Debug/Warning/Error messages
+ const char *file_name = nullptr; // Used for Debug/Warning/Error messages
+ Data *data_array = nullptr; // Array with the Data elements
+ int array_len = -1; // length of the arrays (all three are the same length)
+};
+
+template <class Data, class MatchResult> class UrlMatcher : protected BaseMatcher<Data>
+{
+ typedef BaseMatcher<Data> super;
+
+public:
UrlMatcher(const char *name, const char *filename);
~UrlMatcher();
void Match(RequestData *rdata, MatchResult *result);
@@ -176,30 +197,22 @@ public:
Result NewEntry(matcher_line *line_info);
void Print();
- int
- getNumElements()
- {
- return num_el;
- }
- Data *
- getDataArray()
- {
- return data_array;
- }
+ using super::num_el;
+ using super::matcher_name;
+ using super::file_name;
+ using super::data_array;
+ using super::array_len;
-protected:
+private:
InkHashTable *url_ht;
- char **url_str; // array of url strings
- int *url_value; // array of posion of url strings
- Data *data_array; // data array. Corresponds to re_array
- int array_len; // length of the arrays (all three are the same length)
- int num_el; // number of elements in the table
- const char *matcher_name; // Used for Debug/Warning/Error messages
- const char *file_name; // Used for Debug/Warning/Error messages
+ char **url_str = nullptr; // array of url strings
+ int *url_value = nullptr; // array of posion of url strings
};
-template <class Data, class MatchResult> class RegexMatcher
+template <class Data, class MatchResult> class RegexMatcher : protected BaseMatcher<Data>
{
+ typedef BaseMatcher<Data> super;
+
public:
RegexMatcher(const char *name, const char *filename);
~RegexMatcher();
@@ -208,36 +221,36 @@ public:
Result NewEntry(matcher_line *line_info);
void Print();
- int
- getNumElements()
- {
- return num_el;
- }
- Data *
- getDataArray()
- {
- return data_array;
- }
+ using super::num_el;
+ using super::matcher_name;
+ using super::file_name;
+ using super::data_array;
+ using super::array_len;
protected:
- pcre **re_array; // array of compiled regexs
- char **re_str; // array of uncompiled regex strings
- Data *data_array; // data array. Corresponds to re_array
- int array_len; // length of the arrays (all three are the same length)
- int num_el; // number of elements in the table
- const char *matcher_name; // Used for Debug/Warning/Error messages
- const char *file_name; // Used for Debug/Warning/Error messages
+ pcre **re_array = nullptr; // array of compiled regexs
+ char **re_str = nullptr; // array of uncompiled regex strings
};
template <class Data, class MatchResult> class HostRegexMatcher : public RegexMatcher<Data, MatchResult>
{
+ typedef BaseMatcher<Data> super;
+
public:
HostRegexMatcher(const char *name, const char *filename);
void Match(RequestData *rdata, MatchResult *result);
+
+ using super::num_el;
+ using super::matcher_name;
+ using super::file_name;
+ using super::data_array;
+ using super::array_len;
};
-template <class Data, class MatchResult> class HostMatcher
+template <class Data, class MatchResult> class HostMatcher : protected BaseMatcher<Data>
{
+ typedef BaseMatcher<Data> super;
+
public:
HostMatcher(const char *name, const char *filename);
~HostMatcher();
@@ -246,16 +259,12 @@ public:
Result NewEntry(matcher_line *line_info);
void Print();
- int
- getNumElements()
- {
- return num_el;
- }
- Data *
- getDataArray()
- {
- return data_array;
- }
+ using super::num_el;
+ using super::matcher_name;
+ using super::file_name;
+ using super::data_array;
+ using super::array_len;
+
HostLookup *
getHLookup()
{
@@ -264,42 +273,29 @@ public:
private:
static void PrintFunc(void *opaque_data);
- HostLookup *host_lookup; // Data structure to do the lookups
- Data *data_array; // array of all data items
- int array_len; // the length of the arrays
- int num_el; // the numbe of itmems in the tree
- const char *matcher_name; // Used for Debug/Warning/Error messages
- const char *file_name; // Used for Debug/Warning/Error messages
+ HostLookup *host_lookup = nullptr; // Data structure to do the lookups
};
-template <class Data, class MatchResult> class IpMatcher
+template <class Data, class MatchResult> class IpMatcher : protected BaseMatcher<Data>
{
+ typedef BaseMatcher<Data> super;
+
public:
IpMatcher(const char *name, const char *filename);
- ~IpMatcher();
void Match(sockaddr const *ip_addr, RequestData *rdata, MatchResult *result);
void AllocateSpace(int num_entries);
Result NewEntry(matcher_line *line_info);
void Print();
- int
- getNumElements()
- {
- return num_el;
- }
- Data *
- getDataArray()
- {
- return data_array;
- }
+ using super::num_el;
+ using super::matcher_name;
+ using super::file_name;
+ using super::data_array;
+ using super::array_len;
+private:
static void PrintFunc(void *opaque_data);
- IpMap ip_map; // Data structure to do lookups
- Data *data_array; // array of the data lements with in the table
- int array_len; // size of the arrays
- int num_el; // number of elements in the table
- const char *matcher_name; // Used for Debug/Warning/Error messages
- const char *file_name; // Used for Debug/Warning/Error messages
+ IpMap ip_map; // Data structure to do lookups
};
#define ALLOW_HOST_TABLE 1 << 0
@@ -327,26 +323,31 @@ public:
{
return m_numEntries;
}
+
HostMatcher<Data, MatchResult> *
getHostMatcher()
{
return hostMatch;
}
+
RegexMatcher<Data, MatchResult> *
getReMatcher()
{
return reMatch;
}
+
UrlMatcher<Data, MatchResult> *
getUrlMatcher()
{
return urlMatch;
}
+
IpMatcher<Data, MatchResult> *
getIPMatcher()
{
return ipMatch;
}
+
HostRegexMatcher<Data, MatchResult> *
getHrMatcher()
{
@@ -359,11 +360,12 @@ public:
HostMatcher<Data, MatchResult> *hostMatch;
IpMatcher<Data, MatchResult> *ipMatch;
HostRegexMatcher<Data, MatchResult> *hrMatch;
- const matcher_tags *config_tags;
+
+ const matcher_tags *config_tags = nullptr;
char config_file_path[PATH_NAME_MAX];
- int flags;
- int m_numEntries;
- const char *matcher_name; // Used for Debug/Warning/Error messages
+ int flags = 0;
+ int m_numEntries = 0;
+ const char *matcher_name = "unknown"; // Used for Debug/Warning/Error messages
};
#endif /* _CONTROL_MATCHER_H_ */
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].