Changeset 5bbb4453 in mainline for uspace/app/nav/panel.c


Ignore:
Timestamp:
2021-10-25T00:32:45Z (3 years ago)
Author:
jxsvoboda <5887334+jxsvoboda@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f59212cc
Parents:
97c3c59
git-author:
Jiri Svoboda <jiri@…> (2021-10-19 20:01:48)
git-committer:
jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
Message:

Make sure page is not beyond end of list

Need to correct max_idx correctly for short lists (was getting a
negative number and putting it to a size_t). Need to prevent
page going beyond end of list when moving up a dir and seeking
to the entry of directory we just exited (unless the list is short).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/panel.c

    r97c3c59 r5bbb4453  
    523523        char *olddn;
    524524        size_t pg_size;
     525        size_t max_idx;
    525526        size_t i;
    526527        errno_t rc;
     
    617618                                --panel->page_idx;
    618619                        }
     620
     621                        /* Make sure page is not beyond the end if possible */
     622                        if (panel->entries_cnt > pg_size)
     623                                max_idx = panel->entries_cnt - pg_size;
     624                        else
     625                                max_idx = 0;
     626
     627                        while (panel->page_idx > 0 && panel->page_idx > max_idx) {
     628                                prev = panel_prev(panel->page);
     629                                if (prev == NULL)
     630                                        break;
     631
     632                                panel->page = prev;
     633                                --panel->page_idx;
     634                        }
    619635                }
    620636        }
     
    948964        old_cursor = panel->cursor;
    949965        old_idx = panel->cursor_idx;
    950         max_idx = panel->entries_cnt - rows;
     966
     967        if (panel->entries_cnt > rows)
     968                max_idx = panel->entries_cnt - rows;
     969        else
     970                max_idx = 0;
    951971
    952972        /* Move page by rows entries down (if possible) */
Note: See TracChangeset for help on using the changeset viewer.