diff options
author | Jonathan Lebon <jonathan@jlebon.com> | 2018-07-25 17:51:01 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-07-26 21:01:19 +0000 |
commit | 968e8805b0dd4afbcb25db312f53584b0ec59931 (patch) | |
tree | 3b84bad610b95feb90a08b1a7f0b548987996042 /src/libotutil | |
parent | fcd31a195be0e48709ff44b24ed3b5dc2f4f60e3 (diff) | |
download | ostree-968e8805b0dd4afbcb25db312f53584b0ec59931.tar.gz |
lib: Fix some logic/error-checking code
Using `MAX(0, $x)` here is useless since we're comparing against an
unsigned integer. Just unpack this and only subtract if it's safe to do
so.
Also, explicitly check for `fd >= 0` rather than just `!= -1` to be sure
it's a valid fd. And finally, explicitly check the return value of
`g_input_stream_read_all` as is done everywhere else in the tree and
make it clear that we're purposely ignoring the return value of `_flush`
here, but not in other places.
Discovered by Coverity.
Closes: #1692
Approved by: cgwalters
Diffstat (limited to 'src/libotutil')
-rw-r--r-- | src/libotutil/ot-gpg-utils.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/libotutil/ot-gpg-utils.c b/src/libotutil/ot-gpg-utils.c index 9d5c8d3a..cc5b0ae4 100644 --- a/src/libotutil/ot-gpg-utils.c +++ b/src/libotutil/ot-gpg-utils.c @@ -262,10 +262,8 @@ data_read_cb (void *handle, void *buffer, size_t size) g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), -1); - g_input_stream_read_all (input_stream, buffer, size, - &bytes_read, NULL, &local_error); - - if (local_error != NULL) + if (!g_input_stream_read_all (input_stream, buffer, size, + &bytes_read, NULL, &local_error)) { set_errno_from_gio_error (local_error); g_clear_error (&local_error); @@ -287,7 +285,7 @@ data_write_cb (void *handle, const void *buffer, size_t size) if (g_output_stream_write_all (output_stream, buffer, size, &bytes_written, NULL, &local_error)) { - g_output_stream_flush (output_stream, NULL, &local_error); + (void)g_output_stream_flush (output_stream, NULL, &local_error); } if (local_error != NULL) |