summaryrefslogtreecommitdiff
path: root/src/libudev
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-27 19:09:22 +0100
committerLennart Poettering <lennart@poettering.net>2018-03-02 12:39:07 +0100
commit62d74c78b59f95a76778d9fa8dbe3b098afa2aad (patch)
tree138ea4e336b01254a6766e547fdc10c3728255ef /src/libudev
parent3209c8e6502c095bb7a88a3e915f06dd56228ed4 (diff)
downloadsystemd-62d74c78b59f95a76778d9fa8dbe3b098afa2aad.tar.gz
coccinelle: add reallocarray() coccinelle script
Let's systematically make use of reallocarray() whereever we invoke realloc() with a product of two values.
Diffstat (limited to 'src/libudev')
-rw-r--r--src/libudev/libudev-list.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c
index 29fbdbd450..681e2e445c 100644
--- a/src/libudev/libudev-list.c
+++ b/src/libudev/libudev-list.c
@@ -140,8 +140,7 @@ static int list_search(struct udev_list *list, const char *name)
return -(first+1);
}
-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) {
struct udev_list_entry *entry;
int i = 0;
@@ -152,12 +151,12 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
entry = list->entries[i];
free(entry->value);
- if (value == NULL) {
+ if (!value) {
entry->value = NULL;
return entry;
}
entry->value = strdup(value);
- if (entry->value == NULL)
+ if (!entry->value)
return NULL;
return entry;
}
@@ -165,16 +164,16 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
/* add new name */
entry = new0(struct udev_list_entry, 1);
- if (entry == NULL)
+ if (!entry)
return NULL;
entry->name = strdup(name);
- if (entry->name == NULL)
+ if (!entry->name)
return mfree(entry);
- if (value != NULL) {
+ if (value) {
entry->value = strdup(value);
- if (entry->value == NULL) {
+ if (!entry->value) {
free(entry->name);
return mfree(entry);
}
@@ -189,8 +188,8 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
add = list->entries_max;
if (add < 1)
add = 64;
- entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
- if (entries == NULL) {
+ entries = reallocarray(list->entries, list->entries_max + add, sizeof(struct udev_list_entry *));
+ if (!entries) {
free(entry->name);
free(entry->value);
return mfree(entry);
@@ -213,9 +212,8 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
(list->entries_cur - i) * sizeof(struct udev_list_entry *));
list->entries[i] = entry;
list->entries_cur++;
- } else {
+ } else
udev_list_entry_append(entry, list);
- }
return entry;
}