| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: citrus_db_factory.c,v 1.10 2013/09/14 13:05:51 joerg Exp $ */ | | 1 | /* $NetBSD: citrus_db_factory.c,v 1.11 2021/10/29 10:54:56 nia Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c)2003 Citrus Project, | | 4 | * Copyright (c)2003 Citrus Project, |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #if HAVE_NBTOOL_CONFIG_H | | 29 | #if HAVE_NBTOOL_CONFIG_H |
30 | #include "nbtool_config.h" | | 30 | #include "nbtool_config.h" |
31 | #endif | | 31 | #endif |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | #if defined(LIBC_SCCS) && !defined(lint) | | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | __RCSID("$NetBSD: citrus_db_factory.c,v 1.10 2013/09/14 13:05:51 joerg Exp $"); | | 35 | __RCSID("$NetBSD: citrus_db_factory.c,v 1.11 2021/10/29 10:54:56 nia Exp $"); |
36 | #endif /* LIBC_SCCS and not lint */ | | 36 | #endif /* LIBC_SCCS and not lint */ |
37 | | | 37 | |
38 | #include <assert.h> | | 38 | #include <assert.h> |
39 | #include <stdio.h> | | 39 | #include <stdio.h> |
40 | #include <stdlib.h> | | 40 | #include <stdlib.h> |
41 | #include <string.h> | | 41 | #include <string.h> |
42 | #include <errno.h> | | 42 | #include <errno.h> |
43 | #include <arpa/inet.h> | | 43 | #include <arpa/inet.h> |
44 | #include <sys/types.h> | | 44 | #include <sys/types.h> |
45 | #include <sys/queue.h> | | 45 | #include <sys/queue.h> |
46 | | | 46 | |
47 | #include "citrus_namespace.h" | | 47 | #include "citrus_namespace.h" |
48 | #include "citrus_region.h" | | 48 | #include "citrus_region.h" |
| @@ -264,31 +264,29 @@ int | | | @@ -264,31 +264,29 @@ int |
264 | _citrus_db_factory_serialize(struct _citrus_db_factory *df, const char *magic, | | 264 | _citrus_db_factory_serialize(struct _citrus_db_factory *df, const char *magic, |
265 | struct _region *r) | | 265 | struct _region *r) |
266 | { | | 266 | { |
267 | size_t i, ofs, keyofs, dataofs, nextofs; | | 267 | size_t i, ofs, keyofs, dataofs, nextofs; |
268 | struct _citrus_db_factory_entry *de, **depp, *det; | | 268 | struct _citrus_db_factory_entry *de, **depp, *det; |
269 | | | 269 | |
270 | ofs = 0; | | 270 | ofs = 0; |
271 | /* check whether more than 0 entries exist */ | | 271 | /* check whether more than 0 entries exist */ |
272 | if (df->df_num_entries == 0) { | | 272 | if (df->df_num_entries == 0) { |
273 | dump_header(r, magic, &ofs, 0); | | 273 | dump_header(r, magic, &ofs, 0); |
274 | return 0; | | 274 | return 0; |
275 | } | | 275 | } |
276 | /* allocate hash table */ | | 276 | /* allocate hash table */ |
277 | depp = malloc(sizeof(*depp) * df->df_num_entries); | | 277 | depp = calloc(df->df_num_entries, sizeof(*depp)); |
278 | if (depp == NULL) | | 278 | if (depp == NULL) |
279 | return -1; | | 279 | return -1; |
280 | for (i = 0; i < df->df_num_entries; i++) | | | |
281 | depp[i] = NULL; | | | |
282 | | | 280 | |
283 | /* step1: store the entries which are not conflicting */ | | 281 | /* step1: store the entries which are not conflicting */ |
284 | SIMPLEQ_FOREACH(de, &df->df_entries, de_entry) { | | 282 | SIMPLEQ_FOREACH(de, &df->df_entries, de_entry) { |
285 | de->de_hashvalue %= df->df_num_entries; | | 283 | de->de_hashvalue %= df->df_num_entries; |
286 | de->de_idx = -1; | | 284 | de->de_idx = -1; |
287 | de->de_next = NULL; | | 285 | de->de_next = NULL; |
288 | if (depp[de->de_hashvalue] == NULL) { | | 286 | if (depp[de->de_hashvalue] == NULL) { |
289 | depp[de->de_hashvalue] = de; | | 287 | depp[de->de_hashvalue] = de; |
290 | de->de_idx = (int)de->de_hashvalue; | | 288 | de->de_idx = (int)de->de_hashvalue; |
291 | } | | 289 | } |
292 | } | | 290 | } |
293 | | | 291 | |
294 | /* step2: resolve conflicts */ | | 292 | /* step2: resolve conflicts */ |