2019-11-12 14:55:13

by Michał Lowas-Rzechonek

[permalink] [raw]
Subject: [PATCH BlueZ] mesh: Fix ignored return value

This fixes the following build error when compiling in maintainer mode:

mesh/keyring.c: In function ‘finalize’:
mesh/keyring.c:142:8: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
(void)write(fd, &key, sizeof(key));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
mesh/keyring.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mesh/keyring.c b/mesh/keyring.c
index 9fa7d6bd0..fe292b4a7 100644
--- a/mesh/keyring.c
+++ b/mesh/keyring.c
@@ -140,7 +140,8 @@ static void finalize(const char *fpath, uint16_t net_idx)
l_debug("Finalize %s", fpath);
memcpy(key.old_key, key.new_key, 16);
lseek(fd, 0, SEEK_SET);
- write(fd, &key, sizeof(key));
+ if (write(fd, &key, sizeof(key)) != sizeof(key))
+ goto done;

done:
close(fd);
--
2.19.1


2019-11-13 17:24:38

by Gix, Brian

[permalink] [raw]
Subject: Re: [PATCH BlueZ] mesh: Fix ignored return value

Applied with style-guide corrections:
Blank line ahead of "if"

On Tue, 2019-11-12 at 15:54 +0100, Michał Lowas-Rzechonek wrote:
> This fixes the following build error when compiling in maintainer mode:
>
> mesh/keyring.c: In function ‘finalize’:
> mesh/keyring.c:142:8: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-
> Werror=unused-result]
> (void)write(fd, &key, sizeof(key));
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ---
> mesh/keyring.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mesh/keyring.c b/mesh/keyring.c
> index 9fa7d6bd0..fe292b4a7 100644
> --- a/mesh/keyring.c
> +++ b/mesh/keyring.c
> @@ -140,7 +140,8 @@ static void finalize(const char *fpath, uint16_t net_idx)
> l_debug("Finalize %s", fpath);
> memcpy(key.old_key, key.new_key, 16);
> lseek(fd, 0, SEEK_SET);
> - write(fd, &key, sizeof(key));
> + if (write(fd, &key, sizeof(key)) != sizeof(key))
> + goto done;
>
> done:
> close(fd);