summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2010-08-13 10:56:03 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2010-08-13 10:56:03 -0700
commit5ed312ef6122c7f652c0c07e4357721b4dda8f4f (patch)
tree2f9e6f44104056bf6ee51ef80f5d0ff9adc8b650 /src
parent2aa6d8c6b022f6702437be126eacbe75be5d10aa (diff)
downloadvyatta-cfg-5ed312ef6122c7f652c0c07e4357721b4dda8f4f.tar.gz
vyatta-cfg-5ed312ef6122c7f652c0c07e4357721b4dda8f4f.zip
change all vector/string size to size_t just to be safe.
* would have been a problem if template tree becomes more than 2^32 levels deep or if value strings longer than 2^32 characters are allowed.
Diffstat (limited to 'src')
-rw-r--r--src/cstore/cstore-c.cpp4
-rw-r--r--src/cstore/cstore-varref.cpp8
-rw-r--r--src/cstore/cstore.cpp58
-rw-r--r--src/cstore/unionfs/cstore-unionfs.cpp14
-rw-r--r--src/cstore/unionfs/cstore-unionfs.hpp2
5 files changed, 43 insertions, 43 deletions
diff --git a/src/cstore/cstore-c.cpp b/src/cstore/cstore-c.cpp
index 95f052b..fd818a5 100644
--- a/src/cstore/cstore-c.cpp
+++ b/src/cstore/cstore-c.cpp
@@ -150,7 +150,7 @@ cstore_path_string_to_path_comps(const char *path_str, int *num_comps)
size_t len = strlen(pstr);
vector<string> vec;
char *start = NULL;
- for (unsigned int i = 0; i < len; i++) {
+ for (size_t i = 0; i < len; i++) {
if (pstr[i] == '/') {
if (start) {
pstr[i] = 0;
@@ -168,7 +168,7 @@ cstore_path_string_to_path_comps(const char *path_str, int *num_comps)
}
char **ret = (char **) malloc(sizeof(char *) * vec.size());
if (ret) {
- for (unsigned int i = 0; i < vec.size(); i++) {
+ for (size_t i = 0; i < vec.size(); i++) {
ret[i] = strdup(vec[i].c_str());
}
*num_comps = vec.size();
diff --git a/src/cstore/cstore-varref.cpp b/src/cstore/cstore-varref.cpp
index 46950fa..f00ed38 100644
--- a/src/cstore/cstore-varref.cpp
+++ b/src/cstore/cstore-varref.cpp
@@ -166,7 +166,7 @@ Cstore::VarRef::process_ref(const vector<string>& ref_comps,
// tag node
vector<string> cnodes;
_cstore->cfgPathGetChildNodes(pcomps, cnodes, _active);
- for (unsigned int i = 0; i < cnodes.size(); i++) {
+ for (size_t i = 0; i < cnodes.size(); i++) {
pcomps.push_back(cnodes[i]);
process_ref(rcomps, pcomps, def.def_type);
pcomps.pop_back();
@@ -198,7 +198,7 @@ Cstore::VarRef::process_ref(const vector<string>& ref_comps,
return;
}
string val;
- for (unsigned int i = 0; i < vals.size(); i++) {
+ for (size_t i = 0; i < vals.size(); i++) {
if (val.length() > 0) {
val += " ";
}
@@ -227,7 +227,7 @@ Cstore::VarRef::getValue(string& value, vtw_type_e& def_type)
vector<string> result;
map<string, bool> added;
def_type = ERROR_TYPE;
- for (unsigned int i = 0; i < _paths.size(); i++) {
+ for (size_t i = 0; i < _paths.size(); i++) {
if (_paths[i].first.size() == 0) {
// empty path
continue;
@@ -259,7 +259,7 @@ Cstore::VarRef::getValue(string& value, vtw_type_e& def_type)
def_type = TEXT_TYPE;
}
value = "";
- for (unsigned int i = 0; i < result.size(); i++) {
+ for (size_t i = 0; i < result.size(); i++) {
if (i > 0) {
value += " ";
}
diff --git a/src/cstore/cstore.cpp b/src/cstore/cstore.cpp
index e5de5b4..04e8b27 100644
--- a/src/cstore/cstore.cpp
+++ b/src/cstore/cstore.cpp
@@ -565,7 +565,7 @@ Cstore::getCompletionEnv(const vector<string>& comps, string& env)
// return all template children
get_all_tmpl_child_node_names(ufvec);
}
- for (unsigned int i = 0; i < ufvec.size(); i++) {
+ for (size_t i = 0; i < ufvec.size(); i++) {
if (last_comp == ""
|| ufvec[i].compare(0, last_comp.length(), last_comp) == 0) {
comp_vals.push_back(ufvec[i]);
@@ -576,7 +576,7 @@ Cstore::getCompletionEnv(const vector<string>& comps, string& env)
break;
}
sort(comp_vals.begin(), comp_vals.end());
- for (unsigned int i = 0; i < comp_vals.size(); i++) {
+ for (size_t i = 0; i < comp_vals.size(); i++) {
pair<string, string> hpair(comp_vals[i], "");
push_tmpl_path(hpair.first);
vtw_def cdef;
@@ -619,7 +619,7 @@ Cstore::getCompletionEnv(const vector<string>& comps, string& env)
string cmd_str = ("export " + C_ENV_SHELL_CWORD_COUNT + "="
+ cword_count.str() + "; ");
cmd_str += ("export " + C_ENV_SHELL_CWORDS + "=(");
- for (unsigned int i = 0; i < comps.size(); i++) {
+ for (size_t i = 0; i < comps.size(); i++) {
cmd_str += (" '" + comps[i] + "'");
}
cmd_str += "); ";
@@ -677,7 +677,7 @@ Cstore::getCompletionEnv(const vector<string>& comps, string& env)
}
if (def.def_val_help) {
// has val_help. first separate individual lines.
- unsigned int start = 0, i = 0;
+ size_t start = 0, i = 0;
vector<string> vhelps;
for (i = 0; def.def_val_help[i]; i++) {
if (def.def_val_help[i] == '\n') {
@@ -720,7 +720,7 @@ Cstore::getCompletionEnv(const vector<string>& comps, string& env)
// this var is the array of possible completions
env = (C_ENV_SHAPI_COMP_VALS + "=(");
- for (unsigned int i = 0; i < comp_vals.size(); i++) {
+ for (size_t i = 0; i < comp_vals.size(); i++) {
shell_escape_squotes(comp_vals[i]);
env += ("'" + comp_vals[i] + "' ");
}
@@ -753,7 +753,7 @@ Cstore::getCompletionEnv(const vector<string>& comps, string& env)
string hitems = (C_ENV_SHAPI_HELP_ITEMS + "=(");
// this var is the array of "help strings" corresponding to the items
string hstrs = (C_ENV_SHAPI_HELP_STRS + "=(");
- for (unsigned int i = 0; i < help_pairs.size(); i++) {
+ for (size_t i = 0; i < help_pairs.size(); i++) {
string hi = help_pairs[i].first;
string hs = help_pairs[i].second;
shell_escape_squotes(hi);
@@ -1074,10 +1074,10 @@ Cstore::cfgPathGetDeletedChildNodesDA(const vector<string>& path_comps,
vector<string> wcnodes;
cfgPathGetChildNodesDA(path_comps, wcnodes, false, include_deactivated);
map<string, bool> cmap;
- for (unsigned int i = 0; i < wcnodes.size(); i++) {
+ for (size_t i = 0; i < wcnodes.size(); i++) {
cmap[wcnodes[i]] = true;
}
- for (unsigned int i = 0; i < acnodes.size(); i++) {
+ for (size_t i = 0; i < acnodes.size(); i++) {
if (cmap.find(acnodes[i]) == cmap.end()) {
// in active but not in working
cnodes.push_back(acnodes[i]);
@@ -1102,10 +1102,10 @@ Cstore::cfgPathGetChildNodesStatus(const vector<string>& path_comps,
vector<string> wcnodes;
cfgPathGetChildNodes(path_comps, acnodes, true);
cfgPathGetChildNodes(path_comps, wcnodes, false);
- for (unsigned int i = 0; i < acnodes.size(); i++) {
+ for (size_t i = 0; i < acnodes.size(); i++) {
umap[acnodes[i]] = true;
}
- for (unsigned int i = 0; i < wcnodes.size(); i++) {
+ for (size_t i = 0; i < wcnodes.size(); i++) {
umap[wcnodes[i]] = true;
}
@@ -1141,7 +1141,7 @@ Cstore::cfgPathGetChildNodesStatusDA(const vector<string>& path_comps,
// process deleted nodes first
vector<string> del_nodes;
cfgPathGetDeletedChildNodesDA(path_comps, del_nodes);
- for (unsigned int i = 0; i < del_nodes.size(); i++) {
+ for (size_t i = 0; i < del_nodes.size(); i++) {
cmap[del_nodes[i]] = C_NODE_STATUS_DELETED;
}
@@ -1149,7 +1149,7 @@ Cstore::cfgPathGetChildNodesStatusDA(const vector<string>& path_comps,
vector<string> work_nodes;
cfgPathGetChildNodesDA(path_comps, work_nodes, false);
vector<string> ppath = path_comps;
- for (unsigned int i = 0; i < work_nodes.size(); i++) {
+ for (size_t i = 0; i < work_nodes.size(); i++) {
ppath.push_back(work_nodes[i]);
/* note: in the DA version here, we do NOT check the deactivate state
* when considering the state of the child nodes (which include
@@ -1183,7 +1183,7 @@ bool
Cstore::cfgPathDeactivated(const vector<string>& path_comps, bool active_cfg)
{
vector<string> ppath;
- for (unsigned int i = 0; i < path_comps.size(); i++) {
+ for (size_t i = 0; i < path_comps.size(); i++) {
ppath.push_back(path_comps[i]);
if (cfgPathMarkedDeactivated(ppath, active_cfg)) {
// an ancestor or itself is marked deactivated
@@ -1498,10 +1498,10 @@ Cstore::cfgPathGetEffectiveChildNodes(const vector<string>& path_comps,
vector<string> wcnodes;
cfgPathGetChildNodes(path_comps, acnodes, true);
cfgPathGetChildNodes(path_comps, wcnodes, false);
- for (unsigned int i = 0; i < acnodes.size(); i++) {
+ for (size_t i = 0; i < acnodes.size(); i++) {
cmap[acnodes[i]] = true;
}
- for (unsigned int i = 0; i < wcnodes.size(); i++) {
+ for (size_t i = 0; i < wcnodes.size(); i++) {
cmap[wcnodes[i]] = true;
}
@@ -1583,10 +1583,10 @@ Cstore::cfgPathGetEffectiveValues(const vector<string>& path_comps,
vector<string> nvals;
cfgPathGetValues(path_comps, ovals, true);
cfgPathGetValues(path_comps, nvals, false);
- for (unsigned int i = 0; i < ovals.size(); i++) {
+ for (size_t i = 0; i < ovals.size(); i++) {
vmap[ovals[i]] = true;
}
- for (unsigned int i = 0; i < nvals.size(); i++) {
+ for (size_t i = 0; i < nvals.size(); i++) {
vmap[nvals[i]] = true;
}
@@ -1728,7 +1728,7 @@ Cstore::markCfgPathChanged(const vector<string>& path_comps)
// now mark each level as changed
vector<string> ppath;
- for (unsigned int i = 0; i < path_comps.size(); i++) {
+ for (size_t i = 0; i < path_comps.size(); i++) {
ppath.push_back(path_comps[i]);
if (!cfg_path_exists(ppath, false, false)) {
// this level no longer in working. nothing further.
@@ -1800,7 +1800,7 @@ bool
Cstore::append_tmpl_path(const vector<string>& path_comps, bool& is_tag)
{
is_tag = false;
- for (unsigned int i = 0; i < path_comps.size(); i++) {
+ for (size_t i = 0; i < path_comps.size(); i++) {
push_tmpl_path(path_comps[i]);
if (tmpl_node_exists()) {
// got exact match. continue to next component.
@@ -1893,7 +1893,7 @@ Cstore::get_parsed_tmpl(const vector<string>& path_comps, bool validate_vals,
*/
// first scan up to "full path - 1"
bool valid = true;
- for (unsigned int i = 0; i < (pcomps->size() - 1); i++) {
+ for (size_t i = 0; i < (pcomps->size() - 1); i++) {
if ((*pcomps)[i] == "") {
// only the last component is potentially allowed to be empty str
valid = false;
@@ -2080,12 +2080,12 @@ Cstore::conv_move_args_for_rename(const vector<string>& args,
*
* set the extra levels and then just validate as rename
*/
- unsigned int num_args = args.size();
+ size_t num_args = args.size();
if (num_args < 4) {
// need at least 4 args
return false;
}
- for (unsigned int i = 0; i < (num_args - 4); i++) {
+ for (size_t i = 0; i < (num_args - 4); i++) {
edit_path_comps.push_back(args[i]);
}
rn_args.push_back(args[num_args - 4]); // vif
@@ -2137,7 +2137,7 @@ Cstore::set_cfg_path(const vector<string>& path_comps, bool output)
bool path_exists = true;
// do the set from the top down
SAVE_PATHS;
- for (unsigned int i = 0; i < path_comps.size(); i++) {
+ for (size_t i = 0; i < path_comps.size(); i++) {
// partial path
ppath.push_back(path_comps[i]);
@@ -2145,7 +2145,7 @@ Cstore::set_cfg_path(const vector<string>& path_comps, bool output)
if (!get_parsed_tmpl(ppath, false, def)) {
output_internal("paths[%s,%s]\n", cfg_path_to_str().c_str(),
tmpl_path_to_str().c_str());
- for (unsigned int i = 0; i < ppath.size(); i++) {
+ for (size_t i = 0; i < ppath.size(); i++) {
output_internal(" [%s]\n", ppath[i].c_str());
}
exit_internal("failed to get tmpl during set. not validate first?\n");
@@ -2290,9 +2290,9 @@ Cstore::remove_value_from_multi(const string& value)
}
// remove the value
- unsigned int bc = vvec.size();
+ size_t bc = vvec.size();
vector<string> nvec(vvec.begin(), remove(vvec.begin(), vvec.end(), value));
- unsigned int ac = nvec.size();
+ size_t ac = nvec.size();
// sanity check
if (ac == bc) {
@@ -2441,7 +2441,7 @@ Cstore::get_all_child_node_names(vector<string>& cnodes, bool active_cfg,
{
vector<string> nodes;
get_all_child_node_names_impl(nodes, active_cfg);
- for (unsigned int i = 0; i < nodes.size(); i++) {
+ for (size_t i = 0; i < nodes.size(); i++) {
if (!include_deactivated) {
push_cfg_path(nodes[i]);
bool skip = marked_deactivated(active_cfg);
@@ -2465,7 +2465,7 @@ Cstore::create_default_children()
vector<string> tcnodes;
get_all_tmpl_child_node_names(tcnodes);
bool ret = true;
- for (unsigned int i = 0; i < tcnodes.size(); i++) {
+ for (size_t i = 0; i < tcnodes.size(); i++) {
push_tmpl_path(tcnodes[i]);
vtw_def def;
if (tmpl_node_exists() && tmpl_parse(def)) {
@@ -2496,7 +2496,7 @@ Cstore::get_edit_env(string& env)
vector<string> lvec;
get_edit_level(lvec);
string lvl;
- for (unsigned int i = 0; i < lvec.size(); i++) {
+ for (size_t i = 0; i < lvec.size(); i++) {
if (lvl.length() > 0) {
lvl += " ";
}
diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp
index 1cfccd4..860d553 100644
--- a/src/cstore/unionfs/cstore-unionfs.cpp
+++ b/src/cstore/unionfs/cstore-unionfs.cpp
@@ -101,7 +101,7 @@ _escape_path_name(const string& path)
// special case for empty string
string npath = (path.size() == 0) ? _fs_escape_chars[-1] : "";
- for (unsigned int i = 0; i < path.size(); i++) {
+ for (size_t i = 0; i < path.size(); i++) {
npath += _escape_char(path[i]);
}
@@ -123,7 +123,7 @@ _unescape_path_name(const string& path)
// assume all escape patterns are 3-char
string npath = "";
- for (unsigned int i = 0; i < path.size(); i++) {
+ for (size_t i = 0; i < path.size(); i++) {
if ((path.size() - i) < 3) {
npath += path.substr(i);
break;
@@ -514,7 +514,7 @@ UnionfsCstore::read_value_vec(vector<string>& vvec, bool active_cfg)
* be writing it any more.
*/
// separate values using newline as delimiter
- unsigned int start_idx = 0, idx = 0;
+ size_t start_idx = 0, idx = 0;
for (; idx < ostr.size(); idx++) {
if (ostr[idx] == '\n') {
// got a value
@@ -547,7 +547,7 @@ UnionfsCstore::write_value_vec(const vector<string>& vvec, bool active_cfg)
}
string ostr = "";
- for (unsigned int i = 0; i < vvec.size(); i++) {
+ for (size_t i = 0; i < vvec.size(); i++) {
if (i > 0) {
// subsequent values require delimiter
ostr += "\n";
@@ -734,7 +734,7 @@ UnionfsCstore::unmark_deactivated_descendants()
}
markers.push_back(di->path());
}
- for (unsigned int i = 0; i < markers.size(); i++) {
+ for (size_t i = 0; i < markers.size(); i++) {
b_fs::remove(markers[i]);
}
} catch (...) {
@@ -828,11 +828,11 @@ UnionfsCstore::discard_changes(unsigned long long& num_removed)
// remove and count
num_removed = 0;
- for (unsigned int i = 0; i < files.size(); i++) {
+ for (size_t i = 0; i < files.size(); i++) {
b_fs::remove(files[i]);
num_removed++;
}
- for (unsigned int i = 0; i < directories.size(); i++) {
+ for (size_t i = 0; i < directories.size(); i++) {
num_removed += b_fs::remove_all(directories[i]);
}
} catch (...) {
diff --git a/src/cstore/unionfs/cstore-unionfs.hpp b/src/cstore/unionfs/cstore-unionfs.hpp
index b0e7201..9e49064 100644
--- a/src/cstore/unionfs/cstore-unionfs.hpp
+++ b/src/cstore/unionfs/cstore-unionfs.hpp
@@ -107,7 +107,7 @@ private:
return pop_path(mutable_cfg_path);
};
void append_cfg_path(const vector<string>& path_comps) {
- for (unsigned int i = 0; i < path_comps.size(); i++) {
+ for (size_t i = 0; i < path_comps.size(); i++) {
push_cfg_path(path_comps[i]);
}
};