Try to fix ubsan crash.

This commit is contained in:
Nikolai Kochetov 2020-12-17 10:27:54 +03:00
parent 263aa88cd9
commit bf9c945ce2
2 changed files with 7 additions and 4 deletions

View File

@ -44,10 +44,11 @@ AsyncTaskQueue::~AsyncTaskQueue()
void AsyncTaskQueue::addTask(size_t thread_number, void * data, int fd)
{
if (tasks.count(data))
std::uintptr_t key = reinterpret_cast<uintptr_t>(data);
if (tasks.count(key))
throw Exception("Task was already added to task queue", ErrorCodes::LOGICAL_ERROR);
tasks[data] = TaskData{thread_number, data, fd};
tasks[key] = TaskData{thread_number, data, fd};
epoll_event socket_event;
socket_event.events = EPOLLIN | EPOLLPRI;
@ -80,7 +81,8 @@ AsyncTaskQueue::TaskData AsyncTaskQueue::wait(std::unique_lock<std::mutex> & loc
if (event.data.ptr == pipe_fd)
return {};
auto it = tasks.find(event.data.ptr);
std::uintptr_t key = reinterpret_cast<uintptr_t>(event.data.ptr);
auto it = tasks.find(key);
if (it == tasks.end())
throw Exception("Task was not found in task queue", ErrorCodes::LOGICAL_ERROR);

View File

@ -1,5 +1,6 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <mutex>
#include <atomic>
#include <unordered_map>
@ -26,7 +27,7 @@ private:
int epoll_fd;
int pipe_fd[2];
std::atomic_bool is_finished = false;
std::unordered_map<void *, TaskData> tasks;
std::unordered_map<std::uintptr_t, TaskData> tasks;
public:
AsyncTaskQueue();