# HG changeset patch # User Guido Berhoerster # Date 1565253066 -7200 # Node ID e027dd4409c7e8efa458aea2275428a8a7b46262 # Parent f9501248b6bd48ea2346c670b310d184bf921f55 Handle empty fields correctly when filtering the list of entries diff -r f9501248b6bd -r e027dd4409c7 cmd.c --- a/cmd.c Wed Aug 07 11:28:07 2019 +0200 +++ b/cmd.c Thu Aug 08 10:31:06 2019 +0200 @@ -426,6 +426,11 @@ struct pager *pager = NULL; union list_item **list = NULL; size_t j; + const char *group; + const char *title; + const char *username; + const char *notes; + const char *url; struct record *record; for (i = 1; i < argc; i++) { @@ -482,16 +487,23 @@ pager_printf(pager, "[%s]\n", list[j]->group.group); } else { record = pwfile_get_record(ctx, list[j]->record.id); - if (((group_re == NULL) || (regexec(group_re, - record->group, 0, NULL, 0) == 0)) && - ((title_re == NULL) || (regexec(title_re, - record->title, 0, NULL, 0) == 0)) && - ((username_re == NULL) || (regexec(username_re, - record->username, 0, NULL, 0) == 0)) && - ((notes_re == NULL) || (regexec(notes_re, - record->notes, 0, NULL, 0) == 0)) && - ((url_re == NULL) || (regexec(url_re, - record->url, 0, NULL, 0) == 0))) { + group = (record->group != NULL) ? record->group : ""; + title = (record->title != NULL) ? record->title : ""; + username = (record->username != NULL) ? + record->username : ""; + notes = (record->notes != NULL) ? record->notes : ""; + url = (record->url != NULL) ? record->url : ""; + if (((group_re == NULL) || + (regexec(group_re, group, 0, NULL, 0) == 0)) && + ((title_re == NULL) || + (regexec(title_re, title, 0, NULL, 0) == 0)) && + ((username_re == NULL) || + (regexec(username_re, username, 0, NULL, + 0) == 0)) && + ((notes_re == NULL) || + (regexec(notes_re, notes, 0, NULL, 0) == 0)) && + ((url_re == NULL) || + (regexec(url_re, url, 0, NULL, 0) == 0))) { pager_printf(pager, "%4u %s\n", list[j]->record.id, (list[j]->record.title != NULL) ?