You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all,
I built openbts on a 64-bit system and noticed that in the following code:
double index1 = 0;
while (index1 < output.size()) {
try {
index1 = output.find(search, index1);
if (index1 == string::npos) {
break;
}
output.replace(index1, search.length(), replace);
// We want to scan past the piece we just replaced.
index1 += replace.length();
} catch (...) {
LOG(ERR) << "string replaceAll error"<<LOGVAR(index1)<<LOGVAR(input)<<LOGVAR(search)<<LOGVAR(replace)<<LOGVAR(output);
break;
}
}
index1 of type double is compared to string::npos of type size_t and value -1, which on a amd64 machine are 32-bits and 64-bits long, respectively. So when index1 is finally set to -1, they actually have different values. This means that the if block is never triggered, and an exception is always thrown.
Since openbts has made its control file 64-bit friendly, I guess it would worth the effort to change index1 from double to size_t, and fix this issue.
Here's a little patch:
Fix type of index1 in replaceAll for 64bit safety
--- a/CommonLibs/Utils.cpp
+++ b/CommonLibs/Utils.cpp
@@ -468,7 +468,7 @@
string replaceAll(const std::string input, const std::string search, const std::string replace)
{
string output = input;
- unsigned index1 = 0;
+ size_t index1 = 0;
while (index1 < output.size()) {
try {
Cheers!
The text was updated successfully, but these errors were encountered:
Hi all,
I built openbts on a 64-bit system and noticed that in the following code:
index1
of typedouble
is compared tostring::npos
of typesize_t
and value-1
, which on a amd64 machine are 32-bits and 64-bits long, respectively. So whenindex1
is finally set to-1
, they actually have different values. This means that theif
block is never triggered, and an exception is always thrown.Since openbts has made its control file 64-bit friendly, I guess it would worth the effort to change index1 from
double
tosize_t
, and fix this issue.Here's a little patch:
Cheers!
The text was updated successfully, but these errors were encountered: