From: Yu Watanabe Date: Sat, 12 Apr 2025 12:10:16 +0000 (+0900) Subject: libudev-list: use strdup_to() X-Git-Tag: v258-rc1~792^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=19aa8c0f0e7e30844a421cfcb0b69b7b17c0d4e0;p=thirdparty%2Fsystemd.git libudev-list: use strdup_to() No functional change, just refactoring. --- diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c index a3e972b0ed5..4cfc1f4c087 100644 --- a/src/libudev/libudev-list.c +++ b/src/libudev/libudev-list.c @@ -72,31 +72,21 @@ struct udev_list *udev_list_new(bool unique) { return list; } -struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *_name, const char *_value) { +struct udev_list_entry* udev_list_entry_add(struct udev_list *list, const char *name, const char *value) { _cleanup_(udev_list_entry_freep) struct udev_list_entry *entry = NULL; - _cleanup_free_ char *name = NULL, *value = NULL; assert(list); - assert(_name); + assert(name); - name = strdup(_name); - if (!name) + entry = new0(struct udev_list_entry, 1); + if (!entry) return NULL; - if (_value) { - value = strdup(_value); - if (!value) - return NULL; - } - - entry = new(struct udev_list_entry, 1); - if (!entry) + if (strdup_to(&entry->name, name) < 0) return NULL; - *entry = (struct udev_list_entry) { - .name = TAKE_PTR(name), - .value = TAKE_PTR(value), - }; + if (strdup_to(&entry->value, value) < 0) + return NULL; if (list->unique) { udev_list_entry_free(hashmap_get(list->unique_entries, entry->name));