summaryrefslogtreecommitdiff
path: root/platform/default
diff options
context:
space:
mode:
authorzmiao <miao.zhao@mapbox.com>2020-04-07 16:30:30 +0300
committerGitHub <noreply@github.com>2020-04-07 16:30:30 +0300
commitbf4c7340f32c1e673e6a37b91fc65305757f52d1 (patch)
treec7871ff8901617b09d8a8d45b57334c2198b9b99 /platform/default
parent8986b558eb92e431c773b6033d8ae271eb71de00 (diff)
downloadqtlocation-mapboxgl-bf4c7340f32c1e673e6a37b91fc65305757f52d1.tar.gz
[build] Fix undefined behavour sanitizer (#16375)
* [build] Fix integer overflow runtime error for core part Temporarily remove circle ci UBSAN build precondition * [build] Enable all of the ubsans [build] Check runtime error [build] Update UBSAN_OPTION * [build] Add UBSAN blacklist [build] Ignore system libraries [build] Ignore vendor library * [build] Fix implicit conversion runtime error in core * [build] Fix division by zero runtime error * [build] Add unfixed error to ubsan blacklist * [build] Make UBSAN halt on error Revert "Temporary remove build precondition" * [build] Fix division by zero error * [build] Make UBSAN officially work without FIXME prefix * [build] Fix implicit conversion from int64_t to uint64_t * [build] Rename style test json file name * Address review findings
Diffstat (limited to 'platform/default')
-rw-r--r--platform/default/src/mbgl/storage/offline_database.cpp11
-rw-r--r--platform/default/src/mbgl/util/image.cpp3
-rw-r--r--platform/default/src/mbgl/util/timer.cpp4
3 files changed, 10 insertions, 8 deletions
diff --git a/platform/default/src/mbgl/storage/offline_database.cpp b/platform/default/src/mbgl/storage/offline_database.cpp
index ff283ed105..084b990529 100644
--- a/platform/default/src/mbgl/storage/offline_database.cpp
+++ b/platform/default/src/mbgl/storage/offline_database.cpp
@@ -1275,7 +1275,8 @@ bool OfflineDatabase::evict(uint64_t neededFreeSize, DatabaseSizeChangeStats& st
const uint64_t tileChanges = tileQuery.changes();
// Update current ambient cache size, based on how many bytes were released.
- newAmbientCacheSize = std::max<int64_t>(newAmbientCacheSize - stats.bytesReleased(), 0u);
+ newAmbientCacheSize = std::max<int64_t>(
+ static_cast<int64_t>(newAmbientCacheSize) - static_cast<int64_t>(stats.bytesReleased()), 0u);
// The cached value of offlineTileCount does not need to be updated
// here because only non-offline tiles can be removed by eviction.
@@ -1465,9 +1466,9 @@ uint64_t OfflineDatabase::DatabaseSizeChangeStats::pageSize() const {
}
int64_t OfflineDatabase::DatabaseSizeChangeStats::diff() const {
- const uint64_t currentSize =
- pageSize_ * (db->getPragma<int64_t>("PRAGMA page_count") - db->getPragma<int64_t>("PRAGMA freelist_count"));
- return currentSize - initialSize_;
+ const int64_t currentSize = static_cast<int64_t>(pageSize_) * (db->getPragma<int64_t>("PRAGMA page_count") -
+ db->getPragma<int64_t>("PRAGMA freelist_count"));
+ return currentSize - static_cast<int64_t>(initialSize_);
}
uint64_t OfflineDatabase::DatabaseSizeChangeStats::bytesReleased() const {
@@ -1478,7 +1479,7 @@ uint64_t OfflineDatabase::DatabaseSizeChangeStats::bytesReleased() const {
void OfflineDatabase::updateAmbientCacheSize(DatabaseSizeChangeStats& stats) {
assert(currentAmbientCacheSize);
if (currentAmbientCacheSize) {
- *currentAmbientCacheSize = std::max<int64_t>(*currentAmbientCacheSize + stats.diff(), 0u);
+ *currentAmbientCacheSize = std::max<int64_t>(static_cast<int64_t>(*currentAmbientCacheSize) + stats.diff(), 0u);
}
}
diff --git a/platform/default/src/mbgl/util/image.cpp b/platform/default/src/mbgl/util/image.cpp
index 25063892b7..7d36dbd541 100644
--- a/platform/default/src/mbgl/util/image.cpp
+++ b/platform/default/src/mbgl/util/image.cpp
@@ -12,7 +12,8 @@ PremultipliedImage decodeImage(const std::string& string) {
const size_t size = string.size();
if (size >= 4) {
- uint32_t magic = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
+ uint32_t magic = (static_cast<uint32_t>(data[0]) << 24) | (static_cast<uint32_t>(data[1]) << 16) |
+ (static_cast<uint32_t>(data[2]) << 8) | static_cast<uint32_t>(data[3]);
if (magic == 0x89504E47U) {
return decodePNG(data, size);
}
diff --git a/platform/default/src/mbgl/util/timer.cpp b/platform/default/src/mbgl/util/timer.cpp
index 90a85bfc1f..f59b352842 100644
--- a/platform/default/src/mbgl/util/timer.cpp
+++ b/platform/default/src/mbgl/util/timer.cpp
@@ -60,8 +60,8 @@ Timer::Timer()
Timer::~Timer() = default;
void Timer::start(Duration timeout, Duration repeat, std::function<void()>&& cb) {
- impl->start(std::chrono::duration_cast<Milliseconds>(timeout).count(),
- std::chrono::duration_cast<Milliseconds>(repeat).count(),
+ impl->start(static_cast<uint64_t>(std::chrono::duration_cast<Milliseconds>(timeout).count()),
+ static_cast<uint64_t>(std::chrono::duration_cast<Milliseconds>(repeat).count()),
std::move(cb));
}