xaizek / pms (License: GPLv3+) (since 2018-12-07)
Older version of Practical Music Search written in C++.
Commit be83c4ab68e5c6ada8b082c26aef5a1a9466b3d4

Fix crash in playlist update due to song list and filter mismatch
Author: Kim Tore Jensen
Author date (UTC): 2015-08-22 09:43
Committer name: Kim Tore Jensen
Committer date (UTC): 2015-08-22 09:43
Parent(s): b7d36a649d2339a22a11fb3530399cb6e9e3ca96
Signing key:
Tree: 044341f4627241fdceda137441f321c5cfc4c5d6
File Lines added Lines deleted
src/action.cpp 5 5
src/list.cpp 32 27
File src/action.cpp changed (mode: 100644) (index 4fef9d6..6bf1816)
... ... long Interface::crop(int crop_mode)
980 980 long long
981 981 Interface::remove(Songlist * list) Interface::remove(Songlist * list)
982 982 { {
983 Song * song;
984 vector<Song *> songs;
985 vector<Song *>::iterator i;
983 Song * song;
984 vector<Song *> songs;
985 vector<Song *>::reverse_iterator i;
986 986
987 987 /* FIXME: this check should, perhaps, be done earlier? */ /* FIXME: this check should, perhaps, be done earlier? */
988 988 if (!list) { if (!list) {
 
... ... Interface::remove(Songlist * list)
1000 1000 songs.push_back(song); songs.push_back(song);
1001 1001 } }
1002 1002
1003 i = songs.begin();
1004 while (i != songs.end()) {
1003 i = songs.rbegin();
1004 while (i != songs.rend()) {
1005 1005 if (!pms->comm->remove(list, *i)) { if (!pms->comm->remove(list, *i)) {
1006 1006 return STERR; return STERR;
1007 1007 } }
File src/list.cpp changed (mode: 100644) (index 1095527..887f695)
1 /* vi:set ts=8 sts=8 sw=8:
1 /* vi:set ts=8 sts=8 sw=8 noet:
2 2 * *
3 3 * PMS <<Practical Music Search>> * PMS <<Practical Music Search>>
4 4 * Copyright (C) 2006-2010 Kim Tore Jensen * Copyright (C) 2006-2010 Kim Tore Jensen
 
... ... void Songlist::filter_remove(Filter * f)
373 373 /* /*
374 374 * Clear out the filter list * Clear out the filter list
375 375 */ */
376 void Songlist::filter_clear()
376 void
377 Songlist::filter_clear()
377 378 { {
378 379 vector<Filter *>::iterator it; vector<Filter *>::iterator it;
379 380 unsigned int i; unsigned int i;
380 381
382 if (!filters.size() && filtersongs.size() == songs.size()) {
383 return;
384 }
385
381 386 pms->log(MSG_DEBUG, STOK, "Deleting all filters...\n"); pms->log(MSG_DEBUG, STOK, "Deleting all filters...\n");
382 387
383 388 it = filters.begin(); it = filters.begin();
384 while (it != filters.end())
385 {
389 while (it != filters.end()) {
386 390 delete *it; delete *it;
387 391 ++it; ++it;
388 392 } }
389 393
390 394 filters.clear(); filters.clear();
391 filtersongs.clear();
392
393 for (i = 0; i < songs.size(); i++)
394 {
395 // songs[i]->pos = i;
396 filtersongs.push_back(songs[i]);
397 }
395 filtersongs = songs;
398 396 } }
399 397
400 398 /* /*
 
... ... song_t Songlist::add(Songlist * list)
489 487 song_t song_t
490 488 Songlist::add(Song * song) Songlist::add(Song * song)
491 489 { {
492 vector<Song *>::iterator i;
490 assert(song != NULL);
493 491
494 assert(song != NULL);
495
496 492 if (song->pos == MPD_SONG_NO_NUM || song->pos == static_cast<song_t>(songs.size())) if (song->pos == MPD_SONG_NO_NUM || song->pos == static_cast<song_t>(songs.size()))
497 493 { {
498 494 songs.push_back(song); songs.push_back(song);
 
... ... Songlist::add(Song * song)
502 498 } }
503 499 else else
504 500 { {
505 /* FIXME: random crash here? */
501 /* FIXME: fast way of updating filters instead of disabling
502 * them - maybe some kind of lazy evaluation? */
503 filter_clear();
504
505 /* FIXME: random crash here? */
506 506 if (songs[song->pos]->pos == song->pos) { if (songs[song->pos]->pos == song->pos) {
507 assert(remove(song) == true);
507 if(!remove(songs[song->pos])) {
508 return -1;
509 }
508 510 } }
509 511
510 i = songs.begin() + song->pos;
511 songs.insert(i, song);
512 songs.insert(songs.begin() + song->pos, song);
513 filtersongs.insert(filtersongs.begin() + song->pos, song);
512 514
513 515 /* FIXME: filtersongs does not get updated because of ->pos mismatch, but do we need it anyway? */ /* FIXME: filtersongs does not get updated because of ->pos mismatch, but do we need it anyway? */
514 516 } }
515 517
516 /* FIXME: new function */
518 /* FIXME: new function */
517 519 if (song->time != MPD_SONG_NO_TIME) { if (song->time != MPD_SONG_NO_TIME) {
518 520 length += song->time; length += song->time;
519 521 } }
520 522
521 /* FIXME */
523 /* FIXME */
522 524 seliter = filtersongs.begin(); seliter = filtersongs.begin();
523 525 rseliter = filtersongs.rbegin(); rseliter = filtersongs.rbegin();
524 526
 
... ... Songlist::add(Song * song)
533 535 bool bool
534 536 Songlist::remove(Song * song) Songlist::remove(Song * song)
535 537 { {
536 assert(song != NULL);
538 assert(song != NULL);
537 539
538 540 selectsong(song, false); selectsong(song, false);
539 541
540 542 if (song->pos == MPD_SONG_NO_NUM) { if (song->pos == MPD_SONG_NO_NUM) {
541 543 return remove(match(song->file, 0, filtersongs.size() - 1, MATCH_FILE)); return remove(match(song->file, 0, filtersongs.size() - 1, MATCH_FILE));
542 }
544 }
543 545
544 return remove(song->pos);
546 return remove(song->pos);
545 547 } }
546 548
547 549 /* /*
 
... ... Songlist::remove(int songpos)
569 571
570 572 it = songs.begin() + realsongpos; it = songs.begin() + realsongpos;
571 573 it = songs.erase(it); it = songs.erase(it);
572 while (it != songs.end())
573 {
574 --(*it)->pos;
575 ++it;
574
575 if (role != LIST_ROLE_MAIN) {
576 while (it != songs.end())
577 {
578 --(*it)->pos;
579 ++it;
580 }
576 581 } }
577 582
578 583 it = filtersongs.begin() + songpos; it = filtersongs.begin() + songpos;
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/pms

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/pms

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master