Skip to content

Commit 3e48fcc

Browse files
committed
fix string bugs
1 parent 53fe514 commit 3e48fcc

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

vowpalwabbit/features.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct features { // the core definition of a set of features.
117117
v_array<feature_slice> slice = v_init<feature_slice>();
118118
for (size_t i = 0; i < indicies.size(); i++)
119119
{
120-
feature_slice temp = {values[i], indicies[i] & parse_mask, audit_strings(nullptr, nullptr)};
120+
feature_slice temp = {values[i], indicies[i] & parse_mask, audit_strings("", "")};
121121
if (space_names.size() != 0)
122122
temp.space_name = space_names[i];
123123
slice.push_back(temp);

vowpalwabbit/parse_example.cc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ license as described in the file LICENSE.
1414

1515
using namespace std;
1616

17-
char* copy(const char* base)
18-
{ size_t len = 0;
19-
while (base[len++] != '\0');
20-
char* ret = calloc_or_throw<char>(len);
21-
memcpy(ret,base,len);
22-
return ret;
23-
}
24-
2517
template<bool audit>
2618
class TC_parser
2719
{
@@ -110,7 +102,7 @@ class TC_parser
110102
{ v_array<char> feature_v = v_init<char>();
111103
push_many(feature_v, feature_name.begin, feature_name.end - feature_name.begin);
112104
feature_v.push_back('\0');
113-
fs.space_names.push_back(audit_strings(copy(base), feature_v.begin));
105+
fs.space_names.push_back(audit_strings(base, feature_v.begin));
114106
}
115107
if ((affix_features[index] > 0) && (feature_name.end != feature_name.begin))
116108
{
@@ -138,7 +130,7 @@ class TC_parser
138130
affix_v.push_back('=');
139131
push_many(affix_v, affix_name.begin, affix_name.end - affix_name.begin);
140132
affix_v.push_back('\0');
141-
affix_fs.space_names.push_back(audit_strings(copy((char*)"affix"),affix_v.begin));
133+
fs.space_names.push_back(audit_strings("affix",affix_v.begin));
142134
}
143135
affix >>= 4;
144136
}
@@ -168,7 +160,7 @@ class TC_parser
168160
if (index != ' ') { spelling_v.push_back(index); spelling_v.push_back('_'); }
169161
push_many(spelling_v, spelling_ss.begin, spelling_ss.end - spelling_ss.begin);
170162
spelling_v.push_back('\0');
171-
spell_fs.space_names.push_back(audit_strings(copy((char*)"spelling"),spelling_v.begin));
163+
spell_fs.space_names.push_back(audit_strings("spelling",spelling_v.begin));
172164
}
173165
}
174166
if (namespace_dictionaries[index].size() > 0)
@@ -190,7 +182,7 @@ class TC_parser
190182
ss << index << '_';
191183
for (char* fc=feature_name.begin; fc!=feature_name.end; ++fc) ss << *fc;
192184
ss << '=' << id;
193-
dict_fs.space_names.push_back(audit_strings(copy((char*)"dictionary"), copy(ss.str().c_str())));
185+
dict_fs.space_names.push_back(audit_strings("dictionary", ss.str()));
194186
}
195187
}
196188
}

vowpalwabbit/stagewise_poly.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ base_learner *stagewise_poly_setup(vw &all)
633633

634634
new_options(all, "Stagewise poly options")
635635
("sched_exponent", po::value<float>(), "exponent controlling quantity of included features")
636-
("batch_sz", po::value<uint64_t>(), "multiplier on batch size before including more features")
636+
("batch_sz", po::value<uint32_t>(), "multiplier on batch size before including more features")
637637
("batch_sz_no_doubling", "batch_sz does not double")
638638
#ifdef MAGIC_ARGUMENT
639639
("magic_argument", po::value<float>(), "magical feature flag")

vowpalwabbit/v_array.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ template<class T> struct v_array
7979
void push_back(const T& new_ele)
8080
{ if(end == end_array)
8181
resize(2 * (end_array-begin) + 3);
82-
*(end++) = new_ele;
82+
new (end++) T(new_ele);
8383
}
8484
void push_back_unchecked(const T& new_ele)
85-
{ *(end++) = new_ele;
86-
}
85+
{ new (end++) T(new_ele); }
86+
8787
size_t find_sorted(const T& ele) const //index of the smallest element >= ele, return true if element is in the array
8888
{ size_t size = end - begin;
8989
size_t a = 0;

0 commit comments

Comments
 (0)