Hi, bd1276a3c9 seems to have introduced a segfault when trying to complete a word that doesn't have any match. For example, 'postgres=# z\t' will yield the following backtrace:
#0: psql`pg_strcasecmp(s1="", s2="ACCESS METHOD") at pgstrcasecmp.c:40:39 #1: psql`psql_completion(text=":pgss-", start=0, end=6) at tab-complete.in.c:2033:8 The matching code in tab-complete.in.c: if (matches == NULL) { const pgsql_thing_t *wac; for (wac = words_after_create; wac->name != NULL; wac++) { if (pg_strcasecmp(prev_wd, wac->name) == 0) { psql tries to read the previous word when matches are NULL. However, there's no previous word set here, leading to the segfault. I've attached a patch that checks if the previous word does exist before trying to use it, along with an additional test for this codepath.
v1-0001-Fix-psql-segfault-on-word-completion-without-matc.patch
Description: Binary data