Author: igalic
Date: Thu Sep 22 16:56:50 2011
New Revision: 1174262
URL: http://svn.apache.org/viewvc?rev=1174262&view=rev
Log:
TS-953: consolidate string copy/concat for iocore/cache/.
Modified:
trafficserver/traffic/trunk/iocore/cache/Cache.cc
trafficserver/traffic/trunk/iocore/cache/CachePages.cc
trafficserver/traffic/trunk/iocore/cache/Store.cc
Modified: trafficserver/traffic/trunk/iocore/cache/Cache.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/cache/Cache.cc?rev=1174262&r1=1174261&r2=1174262&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/cache/Cache.cc (original)
+++ trafficserver/traffic/trunk/iocore/cache/Cache.cc Thu Sep 22 16:56:50 2011
@@ -1038,7 +1038,7 @@ Vol::init(char *s, off_t blocks, off_t d
path = ats_strdup(s);
const size_t hash_id_size = strlen(s) + 32;
hash_id = (char *)ats_malloc(hash_id_size);
- ink_strncpy(hash_id, s, hash_id_size);
+ ink_strlcpy(hash_id, s, hash_id_size);
const size_t s_size = strlen(s);
snprintf(hash_id + s_size, (hash_id_size - s_size), " %" PRIu64 ":%" PRIu64
"",
(uint64_t)dir_skip, (uint64_t)blocks);
Modified: trafficserver/traffic/trunk/iocore/cache/CachePages.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/cache/CachePages.cc?rev=1174262&r1=1174261&r2=1174262&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/cache/CachePages.cc (original)
+++ trafficserver/traffic/trunk/iocore/cache/CachePages.cc Thu Sep 22 16:56:50
2011
@@ -73,10 +73,8 @@ struct ShowCache: public ShowCont {
// process the query string
if (u->query_get(&query_len)) {
- strncpy(query, u->query_get(&query_len), query_len);
- query[query_len] = '\0';
- strncpy(unescapedQuery, query, query_len);
- unescapedQuery[query_len] = '\0';
+ ink_strlcpy(query, u->query_get(&query_len), query_len);
+ ink_strlcpy(unescapedQuery, query, query_len);
query_len = unescapifyStr(query);
@@ -103,9 +101,7 @@ struct ShowCache: public ShowCont {
}
// initialize url array
show_cache_urlstrs = NEW(new char[nstrings + 1][500]);
- for (int si = 0; si < nstrings + 1; si++)
- for (int sj = 0; sj < 500; sj++)
- show_cache_urlstrs[si][sj] = '\0'; // zeroing out mem
+ memset(show_cache_urlstrs, '\0', (nstrings + 1) * 500 * sizeof (char *));
char *q, *t;
p = strstr(unescapedQuery, "url=");
@@ -119,8 +115,7 @@ struct ShowCache: public ShowCont {
q = strstr(p, "%0D%0A"); // we used this in the JS to separate
urls
if (!q)
q = t;
- strncpy(show_cache_urlstrs[s], p, q - p);
- show_cache_urlstrs[s][q - p] = '\0';
+ ink_strlcpy(show_cache_urlstrs[s], p, sizeof(show_cache_urlstrs[s]));
p = q + 6; // +6 ==> strlen(%0D%0A)
}
}
Modified: trafficserver/traffic/trunk/iocore/cache/Store.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/cache/Store.cc?rev=1174262&r1=1174261&r2=1174262&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/cache/Store.cc (original)
+++ trafficserver/traffic/trunk/iocore/cache/Store.cc Thu Sep 22 16:56:50 2011
@@ -260,7 +260,7 @@ Store::read_config(int fd)
// inside ink_cache_init() which is called AFTER
// initialize_store().
//
- // ink_strncpy(p, cache_system_config_directory, sizeof(p));
+ // ink_strlcpy(p, cache_system_config_directory, sizeof(p));
IOCORE_ReadConfigString(storage_file,
"proxy.config.cache.storage_filename", PATH_NAME_MAX);
Layout::relative_to(storage_path, PATH_NAME_MAX,
Layout::get()->sysconfdir, storage_file);
Debug("cache_init", "Store::read_config, fd = -1, \"%s\"", storage_path);