int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-catalog.XXXXXX";
_cleanup_close_ int fd = -1;
- _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+ _cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
if (!getenv("SYSTEMD_LOG_LEVEL"))
log_set_max_level(LOG_CRIT);
- assert_se(h = hashmap_new(&catalog_hash_ops));
+ assert_se(h = ordered_hashmap_new(&catalog_hash_ops));
fd = mkostemp_safe(name);
assert_se(fd >= 0);
}
static int finish_item(
- Hashmap *h,
+ OrderedHashmap *h,
sd_id128_t id,
const char *language,
char *payload, size_t payload_size) {
strcpy(i->language, language);
}
- prev = hashmap_get(h, i);
+ prev = ordered_hashmap_get(h, i);
if (prev) {
/* Already have such an item, combine them */
combined = combine_entries(payload, prev);
if (!combined)
return log_oom();
- if (hashmap_update(h, i, combined) < 0)
+ if (ordered_hashmap_update(h, i, combined) < 0)
return log_oom();
combined = NULL;
} else {
if (!combined)
return log_oom();
- if (hashmap_put(h, i, combined) < 0)
+ if (ordered_hashmap_put(h, i, combined) < 0)
return log_oom();
i = NULL;
combined = NULL;
return 0;
}
-int catalog_import_file(Hashmap *h, const char *path) {
+int catalog_import_file(OrderedHashmap *h, const char *path) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *payload = NULL;
size_t payload_size = 0, payload_allocated = 0;
_cleanup_strv_free_ char **files = NULL;
char **f;
_cleanup_(strbuf_cleanupp) struct strbuf *sb = NULL;
- _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+ _cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
_cleanup_free_ CatalogItem *items = NULL;
ssize_t offset;
char *payload;
int r;
int64_t sz;
- h = hashmap_new(&catalog_hash_ops);
+ h = ordered_hashmap_new(&catalog_hash_ops);
sb = strbuf_new();
if (!h || !sb)
return log_oom();
return log_error_errno(r, "Failed to import file '%s': %m", *f);
}
- if (hashmap_size(h) <= 0) {
+ if (ordered_hashmap_size(h) <= 0) {
log_info("No items in catalog.");
return 0;
} else
- log_debug("Found %u items in catalog.", hashmap_size(h));
+ log_debug("Found %u items in catalog.", ordered_hashmap_size(h));
- items = new(CatalogItem, hashmap_size(h));
+ items = new(CatalogItem, ordered_hashmap_size(h));
if (!items)
return log_oom();
n = 0;
- HASHMAP_FOREACH_KEY(payload, i, h, j) {
+ ORDERED_HASHMAP_FOREACH_KEY(payload, i, h, j) {
log_debug("Found " SD_ID128_FORMAT_STR ", language %s",
SD_ID128_FORMAT_VAL(i->id),
isempty(i->language) ? "C" : i->language);
items[n++] = *i;
}
- assert(n == hashmap_size(h));
+ assert(n == ordered_hashmap_size(h));
typesafe_qsort(items, n, catalog_compare_func);
strbuf_complete(sb);
#include "hashmap.h"
#include "strbuf.h"
-int catalog_import_file(Hashmap *h, const char *path);
+int catalog_import_file(OrderedHashmap *h, const char *path);
int catalog_update(const char* database, const char* root, const char* const* dirs);
int catalog_get(const char* database, sd_id128_t id, char **data);
int catalog_list(FILE *f, const char* database, bool oneline);
NULL
};
-static Hashmap* test_import(const char* contents, ssize_t size, int code) {
+static OrderedHashmap* test_import(const char* contents, ssize_t size, int code) {
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-catalog.XXXXXX";
_cleanup_close_ int fd;
- Hashmap *h;
+ OrderedHashmap *h;
if (size < 0)
size = strlen(contents);
- assert_se(h = hashmap_new(&catalog_hash_ops));
+ assert_se(h = ordered_hashmap_new(&catalog_hash_ops));
fd = mkostemp_safe(name);
assert_se(fd >= 0);
}
static void test_catalog_import_invalid(void) {
- _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+ _cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
h = test_import("xxx", -1, -EINVAL);
- assert_se(hashmap_isempty(h));
+ assert_se(ordered_hashmap_isempty(h));
}
static void test_catalog_import_badid(void) {
- _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+ _cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
const char *input =
"-- 0027229ca0644181a76c4e92458afaff dededededededededededededededede\n" \
"Subject: message\n" \
}
static void test_catalog_import_one(void) {
- _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+ _cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
char *payload;
Iterator j;
"payload\n";
h = test_import(input, -1, 0);
- assert_se(hashmap_size(h) == 1);
+ assert_se(ordered_hashmap_size(h) == 1);
- HASHMAP_FOREACH(payload, h, j) {
+ ORDERED_HASHMAP_FOREACH(payload, h, j) {
printf("expect: %s\n", expect);
printf("actual: %s\n", payload);
assert_se(streq(expect, payload));
}
static void test_catalog_import_merge(void) {
- _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+ _cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
char *payload;
Iterator j;
"override payload\n";
h = test_import(input, -1, 0);
- assert_se(hashmap_size(h) == 1);
+ assert_se(ordered_hashmap_size(h) == 1);
- HASHMAP_FOREACH(payload, h, j) {
+ ORDERED_HASHMAP_FOREACH(payload, h, j) {
assert_se(streq(combined, payload));
}
}
static void test_catalog_import_merge_no_body(void) {
- _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+ _cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
char *payload;
Iterator j;
"payload\n";
h = test_import(input, -1, 0);
- assert_se(hashmap_size(h) == 1);
+ assert_se(ordered_hashmap_size(h) == 1);
- HASHMAP_FOREACH(payload, h, j) {
+ ORDERED_HASHMAP_FOREACH(payload, h, j) {
assert_se(streq(combined, payload));
}
}