Skip to content

Commit 9b191f9

Browse files
committed
StorageLocation: Fix release builds
A bad_malloc was thrown around warning_path string and file construction. Using auto with QStringBuilder is dangerous...
1 parent d929f92 commit 9b191f9

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/core/storage_location.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,16 @@ std::vector<QString> getExternalFilesDirs(jstring* type)
101101
type);
102102

103103
QAndroidJniEnvironment jni;
104-
jni->ExceptionClear();
105-
106104
const auto length = jni->GetArrayLength(external_files_dirs.object<jarray>());
105+
107106
std::vector<QString> locations;
108107
locations.reserve(std::size_t(length));
109108
for (auto i = 0; i < length; ++i)
110109
{
111110
auto location_jni = jni->GetObjectArrayElement(external_files_dirs.object<jobjectArray>(), i);
112111
auto location = QAndroidJniObject{ location_jni }.toString();
113112

114-
const auto warning_path = location + QLatin1String("/README.html");
113+
const auto warning_path = QString(location + QLatin1String("/README.html"));
115114
QFile warning(warning_path);
116115
if (warning.open(QIODevice::WriteOnly | QIODevice::Truncate))
117116
{
@@ -218,9 +217,9 @@ std::shared_ptr<const std::vector<StorageLocation>> buildLocationCache()
218217
}
219218

220219
auto locations = std::make_shared<std::vector<StorageLocation>>();
221-
locations->reserve(1 + locations_normal.size()
222-
+ locations_application.size()
223-
+ locations_readonly.size());
220+
locations->reserve(locations_normal.size()
221+
+ locations_application.size()
222+
+ locations_readonly.size());
224223
for (const auto& path : locations_normal)
225224
locations->emplace_back(path, StorageLocation::HintNormal);
226225
for (const auto& path : locations_application)
@@ -247,6 +246,7 @@ std::shared_ptr<const std::vector<StorageLocation>> StorageLocation::knownLocati
247246
locations = Android::buildLocationCache();
248247
Android::locations_cache = locations;
249248
}
249+
Q_ASSERT(locations);
250250
return locations;
251251
#else
252252
auto locations = std::make_shared<std::vector<StorageLocation>>();

src/core/storage_location.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ class StorageLocation
7373
static QString fileHintTextTemplate(Hint hint);
7474

7575

76-
/** Returns the known locations for documents. */
76+
/**
77+
* Returns the known locations for documents.
78+
*
79+
* The returned shared-ptr will always have an object, even if it is an empty list.
80+
*/
7781
static std::shared_ptr<const std::vector<StorageLocation>> knownLocations();
7882

7983

0 commit comments

Comments
 (0)