Simplify wordsplit code a bit

These changes pacify gcc -Wanalyzer-null-dereference on x86-64 gcc
11.2.1 20210728 (Red Hat 11.2.1-1).
* lib/wordsplit.c (wsnode_tail): Remove unnecessary test.
(coalesce_segment): Coalesce calls to wsnode_len.
This commit is contained in:
Paul Eggert
2021-09-19 07:34:53 -07:00
parent c5b86d7672
commit 4f3824743f

View File

@@ -472,7 +472,7 @@ wsnode_remove (struct wordsplit *wsp, struct wordsplit_node *node)
static struct wordsplit_node * static struct wordsplit_node *
wsnode_tail (struct wordsplit_node *p) wsnode_tail (struct wordsplit_node *p)
{ {
while (p && p->next) while (p->next)
p = p->next; p = p->next;
return p; return p;
} }
@@ -573,15 +573,15 @@ coalesce_segment (struct wordsplit *wsp, struct wordsplit_node *node)
char *buf, *cur; char *buf, *cur;
int stop; int stop;
if (!(node->flags & _WSNF_JOIN)) for (p = node; p->flags & _WSNF_JOIN; )
return 0;
for (p = node; p && (p->flags & _WSNF_JOIN); p = p->next)
{ {
len += wsnode_len (p); len += wsnode_len (p);
p = p->next;
if (!p)
break;
} }
if (p) if (p == node)
len += wsnode_len (p); return 0;
end = p; end = p;
buf = malloc (len + 1); buf = malloc (len + 1);