mtree -O: Fix not descending on hash collisions

MFC after:	2 weeks
Obtained from:	NetBSD (nakayama)
This commit is contained in:
Bryan Drewery 2019-09-12 20:46:46 +00:00
parent cd38a86c63
commit 62a4b30239
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=352265

View file

@ -1,4 +1,4 @@
/* $NetBSD: only.c,v 1.2 2013/02/05 00:59:03 christos Exp $ */ /* $NetBSD: only.c,v 1.3 2017/09/07 04:04:13 nakayama Exp $ */
/*- /*-
* Copyright (c) 2013 The NetBSD Foundation, Inc. * Copyright (c) 2013 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: only.c,v 1.2 2013/02/05 00:59:03 christos Exp $"); __RCSID("$NetBSD: only.c,v 1.3 2017/09/07 04:04:13 nakayama Exp $");
#endif #endif
#include <sys/param.h> #include <sys/param.h>
@ -89,11 +89,14 @@ static void
hash_insert(char *str, uint32_t h) hash_insert(char *str, uint32_t h)
{ {
struct hentry *e; struct hentry *e;
char *x;
if ((e = malloc(sizeof(*e))) == NULL) if ((e = malloc(sizeof(*e))) == NULL)
mtree_err("memory allocation error"); mtree_err("memory allocation error");
if ((x = strdup(str)) == NULL)
mtree_err("memory allocation error");
e->str = str; e->str = x;
e->hash = h; e->hash = h;
e->next = table[h]; e->next = table[h];
table[h] = e; table[h] = e;
@ -110,10 +113,7 @@ fill(char *str)
*ptr = '\0'; *ptr = '\0';
if (!hash_find(str, &h)) { if (!hash_find(str, &h)) {
char *x = strdup(str); hash_insert(str, h);
if (x == NULL)
mtree_err("memory allocation error");
hash_insert(x, h);
fill(str); fill(str);
} }
*ptr = '/'; *ptr = '/';
@ -135,6 +135,7 @@ load_only(const char *fname)
err(1, "Duplicate entry %s", line); err(1, "Duplicate entry %s", line);
hash_insert(line, h); hash_insert(line, h);
fill(line); fill(line);
free(line);
} }
fclose(fp); fclose(fp);