From: Takashi Sakamoto Date: Sat, 28 Aug 2021 02:51:36 +0000 (+0900) Subject: ctl/rawmidi/hwdep: fix compiler warning due to uninitialized variables X-Git-Tag: v0.2.1~2 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=5ca1c21e269e571396a636cae0f0d84c8e4a9eb5;p=alsa-gobject.git ctl/rawmidi/hwdep: fix compiler warning due to uninitialized variables In some libraries, the local variable of udev enumerate is carelessly uninitialized. As a result, compiler generates warnings, like: ../src/ctl/query.c: In function ‘alsactl_get_card_id_list’: ../src/ctl/query.c:131:8: warning: ‘enumerator’ may be used uninitialized in this function [-Wmaybe-uninitialized] 131 | if (enumerator == NULL) | ^ This commit fixes the bug. Fixes: d1936fbbe7e2 ("ctl: add global method to get list of available sound cards") Fixes: cb128c5b59e0 ("rawmidi; add global method to get list of rawmidi device for sound card") Fixes: d4a9f6735d05 ("hwdep: add global method to get list of hwdep devices in sound card") Signed-off-by: Takashi Sakamoto --- diff --git a/src/ctl/query.c b/src/ctl/query.c index 3fc0083..cfaef2a 100644 --- a/src/ctl/query.c +++ b/src/ctl/query.c @@ -118,7 +118,7 @@ static int compare_guint(const void *l, const void *r) void alsactl_get_card_id_list(guint **entries, gsize *entry_count, GError **error) { - struct udev_enumerate *enumerator; + struct udev_enumerate *enumerator = NULL; struct udev_list_entry *entry, *entry_list; unsigned int count; unsigned int index; @@ -128,7 +128,7 @@ void alsactl_get_card_id_list(guint **entries, gsize *entry_count, g_return_if_fail(error == NULL || *error == NULL); prepare_udev_enum(&enumerator, error); - if (enumerator == NULL) + if (*error == NULL) return; entry_list = udev_enumerate_get_list_entry(enumerator); diff --git a/src/hwdep/query.c b/src/hwdep/query.c index 88c96f8..d86c2a0 100644 --- a/src/hwdep/query.c +++ b/src/hwdep/query.c @@ -141,7 +141,7 @@ static unsigned int calculate_digits(unsigned int number) void alsahwdep_get_device_id_list(guint card_id, guint **entries, gsize *entry_count, GError **error) { - struct udev_enumerate *enumerator; + struct udev_enumerate *enumerator = NULL; unsigned int length; char *prefix; struct udev_list_entry *entry, *entry_list; @@ -154,7 +154,7 @@ void alsahwdep_get_device_id_list(guint card_id, guint **entries, prepare_udev_enum(&enumerator, error); if (*error != NULL) - goto end; + return; length = strlen(PREFIX_SYSNAME_TEMPLATE) + calculate_digits(card_id) + 1; prefix = g_malloc0(length); diff --git a/src/rawmidi/query.c b/src/rawmidi/query.c index 551fa03..46b624c 100644 --- a/src/rawmidi/query.c +++ b/src/rawmidi/query.c @@ -141,7 +141,7 @@ static unsigned int calculate_digits(unsigned int number) void alsarawmidi_get_device_id_list(guint card_id, guint **entries, gsize *entry_count, GError **error) { - struct udev_enumerate *enumerator; + struct udev_enumerate *enumerator = NULL; unsigned int length; char *prefix; struct udev_list_entry *entry, *entry_list; @@ -154,7 +154,7 @@ void alsarawmidi_get_device_id_list(guint card_id, guint **entries, prepare_udev_enum(&enumerator, error); if (*error != NULL) - goto end; + return; length = strlen(PREFIX_SYSNAME_TEMPLATE) + calculate_digits(card_id) + 1; prefix = g_malloc0(length);