Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
Пофиксил краш при обновлении треда
Browse files Browse the repository at this point in the history
  • Loading branch information
bcskda committed Nov 7, 2017
1 parent f27be63 commit 29fa95d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
15 changes: 6 additions & 9 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ ThreadView::ThreadView(WINDOW *win, const Makaba::Thread &thread):
thread_(thread),
size_(thread.nposts),
buffer_(),
posts_(thread.nposts),
posts_(),
pos_(0)
{
clog << "New ThreadView\n";
Expand All @@ -122,14 +122,14 @@ ThreadView::ThreadView(WINDOW *win, const Makaba::Thread &thread):
<< " entries for " << size_ << " posts\n";
}

void ThreadView::append(int from) {
void ThreadView::append(long long from) {
// Разбиваем UnicodeString по концам строк, копируем в другую UnicodeString и конвертим в std::string
UnicodeString unis, unitmp;
string stds;
for (long long i = from; i < thread_.nposts; i++) {
clog << "append Post # " << i << endl;
unis = UnicodeString::fromUTF8(PostView(thread_[i]).print_buf());
posts_[i].begin = buffer_.size();
posts_[i].lines = 1;
posts_.push_back({ (long long)buffer_.size(), 1 });
int32_t l = 0;
for (int32_t j = 0; j < unis.length(); j++)
if (unis[j] == '\n' || j - l > maxx_ - 2) {
Expand Down Expand Up @@ -174,10 +174,8 @@ void ThreadView::update() {
maxy_ = y;
maxx_ = x;
}
else {
this->append(size_);
size_ = thread_.nposts;
}
this->append(size_);
size_ = thread_.nposts;
}

int ThreadView::size() const {
Expand Down Expand Up @@ -421,7 +419,6 @@ string thread_send_post_wrapper(

void *thread_hook_on_update(void *userdata, const char *raw)
{
clog << "[hook on_update] Called with \"" << raw << "\"\n";
Makaba::Thread *thread = (Makaba::Thread *)userdata;
if (writeJsonCache(*thread, raw) == -1) {
fprintf(stderr, "[%s] Error: writeJsonCache() failed\n",
Expand Down
6 changes: 3 additions & 3 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class PostView : public BasicView {
};

struct PostInfo {
int begin;
int lines;
long long begin;
long long lines;
};

class ThreadView : public BasicView {
ThreadView();
void append(int from);
void append(long long from);
const Makaba::Thread &thread_;
long long size_;
vector<string> buffer_;
Expand Down

0 comments on commit 29fa95d

Please sign in to comment.