From 7321988ed77023d53922c2be61a6fc8a51ed7ddb Mon Sep 17 00:00:00 2001 From: Diego Ongaro Date: Thu, 3 Sep 2020 12:06:02 -0700 Subject: [PATCH 5/5] find: Handle possible errors from strcoll --- find/ftsfind.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/find/ftsfind.c b/find/ftsfind.c index 43799b57..4d05834b 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -520,8 +520,19 @@ consider_visiting (FTS *p, FTSENT *ent) } static int compare(FTSENT const **a, FTSENT const **b) { + /* According to POSIX, strcoll may signal an error through errno (but glib's + * strcoll doesn't seem to do this). This function saves and restores the + * original errno in case FTS needs it, and it falls back to strcmp if + * strcoll fails. */ assert ((*a)->fts_parent == (*b)->fts_parent); - return strcoll((*a)->fts_name, (*b)->fts_name); + int saved_errno = errno; + errno = 0; + int r = strcoll((*a)->fts_name, (*b)->fts_name); + if (0 != errno) { + r = strcmp((*a)->fts_name, (*b)->fts_name); + } + errno = saved_errno; + return r; } -- 2.27.0