[alsa-devel] [PATCH alsa-lib 1/2] pcm_share: Fix compiler warnings -Wunused-result
Before this commit, compilation of `pcm_share` causes warnings "ignoring return value" for several `read` and `write` operations:
~~~~ pcm_share.c: In function '_snd_pcm_share_missing': pcm_share.c:293:5: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result] read(share->slave_socket, buf, 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <...> ~~~~
However, ignoring return values in these use-cases is safe and optimal, because `read` and `write` operations are executed upon descriptors, created with `socketpair()` and `pipe()`.
This commit fixes the warnings by introducing the return value with the attribute `unused` (for details, see [1]). The macro, used in this commit, is defined at `global.h`:
~~~~ define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) ~~~~
I explicitly checked the objdump: this commit doesn't change the machine code, related to the modified C code lines. The execution performance is not affected.
[1] https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/Common-Variable-Attributes.html
Signed-off-by: Kirill Marinushkin kmarinushkin@birdec.tech --- src/pcm/pcm_share.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/pcm/pcm_share.c b/src/pcm/pcm_share.c index 5a540c4f..9592e003 100644 --- a/src/pcm/pcm_share.c +++ b/src/pcm/pcm_share.c @@ -287,17 +287,18 @@ static snd_pcm_uframes_t _snd_pcm_share_missing(snd_pcm_t *pcm)
update_poll: if (ready != share->ready) { + int un ATTRIBUTE_UNUSED; char buf[1]; if (pcm->stream == SND_PCM_STREAM_PLAYBACK) { if (ready) - read(share->slave_socket, buf, 1); + un = read(share->slave_socket, buf, 1); else - write(share->client_socket, buf, 1); + un = write(share->client_socket, buf, 1); } else { if (ready) - write(share->slave_socket, buf, 1); + un = write(share->slave_socket, buf, 1); else - read(share->client_socket, buf, 1); + un = read(share->client_socket, buf, 1); } share->ready = ready; } @@ -404,8 +405,9 @@ static void *snd_pcm_share_thread(void *data) err = poll(pfd, 2, -1); Pthread_mutex_lock(&slave->mutex); if (pfd[0].revents & POLLIN) { + int un ATTRIBUTE_UNUSED; char buf[1]; - read(pfd[0].fd, buf, 1); + un = read(pfd[0].fd, buf, 1); } } else { slave->polling = 0;
Before this commit, compilation of `pcm_dmix` causes warnings "ignoring return value" for `fgets` operations:
~~~~ pcm_dmix_i386.c:108:5: warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result] fgets(line, sizeof(line), in); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
This commit fixes the warnings.
Signed-off-by: Kirill Marinushkin kmarinushkin@birdec.tech --- src/pcm/pcm_dmix_i386.c | 3 ++- src/pcm/pcm_dmix_x86_64.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/pcm/pcm_dmix_i386.c b/src/pcm/pcm_dmix_i386.c index 1ab983a8..81265517 100644 --- a/src/pcm/pcm_dmix_i386.c +++ b/src/pcm/pcm_dmix_i386.c @@ -105,7 +105,8 @@ static void mix_select_callbacks(snd_pcm_direct_t *dmix) in = fopen("/proc/cpuinfo", "r"); if (in) { while (!feof(in)) { - fgets(line, sizeof(line), in); + if (!fgets(line, sizeof(line), in)) + continue; if (!strncmp(line, "processor", 9)) smp++; else if (!strncmp(line, "flags", 5)) { diff --git a/src/pcm/pcm_dmix_x86_64.c b/src/pcm/pcm_dmix_x86_64.c index 34c40d4e..c96af69b 100644 --- a/src/pcm/pcm_dmix_x86_64.c +++ b/src/pcm/pcm_dmix_x86_64.c @@ -88,7 +88,8 @@ static void mix_select_callbacks(snd_pcm_direct_t *dmix) in = fopen("/proc/cpuinfo", "r"); if (in) { while (!feof(in)) { - fgets(line, sizeof(line), in); + if (!fgets(line, sizeof(line), in)) + continue; if (!strncmp(line, "processor", 9)) smp++; }
On Thu, 15 Nov 2018 08:19:56 +0100, Kirill Marinushkin wrote:
Before this commit, compilation of `pcm_share` causes warnings "ignoring return value" for several `read` and `write` operations:
pcm_share.c: In function '_snd_pcm_share_missing': pcm_share.c:293:5: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result] read(share->slave_socket, buf, 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <...>
However, ignoring return values in these use-cases is safe and optimal, because `read` and `write` operations are executed upon descriptors, created with `socketpair()` and `pipe()`.
This commit fixes the warnings by introducing the return value with the attribute `unused` (for details, see [1]). The macro, used in this commit, is defined at `global.h`:
define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
I explicitly checked the objdump: this commit doesn't change the machine code, related to the modified C code lines. The execution performance is not affected.
[1] https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/Common-Variable-Attributes.html
Signed-off-by: Kirill Marinushkin kmarinushkin@birdec.tech
Which compiler version? I'm using gcc 8.2.1, and couldn't get any warnings like the above.
thanks,
Takashi
Hello Takashi,
On 11/15/18 12:08, Takashi Iwai wrote:
On Thu, 15 Nov 2018 08:19:56 +0100, Kirill Marinushkin wrote:
Before this commit, compilation of `pcm_share` causes warnings "ignoring return value" for several `read` and `write` operations:
pcm_share.c: In function '_snd_pcm_share_missing': pcm_share.c:293:5: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result] read(share->slave_socket, buf, 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <...>
Which compiler version? I'm using gcc 8.2.1, and couldn't get any warnings like the above.
thanks,
Takashi
My gcc version is 6.4.0
Best Regards, Kirill
On Thu, 15 Nov 2018 18:30:18 +0100, Kirill Marinushkin wrote:
Hello Takashi,
On 11/15/18 12:08, Takashi Iwai wrote:
On Thu, 15 Nov 2018 08:19:56 +0100, Kirill Marinushkin wrote:
Before this commit, compilation of `pcm_share` causes warnings "ignoring return value" for several `read` and `write` operations:
pcm_share.c: In function '_snd_pcm_share_missing': pcm_share.c:293:5: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result] read(share->slave_socket, buf, 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <...>
Which compiler version? I'm using gcc 8.2.1, and couldn't get any warnings like the above.
thanks,
Takashi
My gcc version is 6.4.0
Then I believe gcc has fixed itself not to warn this kind of things any longer.
Takashi
participants (2)
-
Kirill Marinushkin
-
Takashi Iwai