[easytag] Refactor GIO error checking in C++ wrapper
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Refactor GIO error checking in C++ wrapper
- Date: Thu, 17 Apr 2014 21:13:53 +0000 (UTC)
commit dd99ec94f5d46e433cf785ba5bfc849dd0987f78
Author: David King <amigadave amigadave com>
Date: Thu Apr 17 22:01:43 2014 +0100
Refactor GIO error checking in C++ wrapper
Check the return value of g_output_stream_write_all().
Found with Coverity (CID 1203401, CID 1203402 and CID 1203403)
src/gio_wrapper.cc | 38 +++++++++++++++++++-------------------
1 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/src/gio_wrapper.cc b/src/gio_wrapper.cc
index 763cfa4..24b31ac 100644
--- a/src/gio_wrapper.cc
+++ b/src/gio_wrapper.cc
@@ -227,10 +227,15 @@ GIO_IOStream::writeBlock (TagLib::ByteVector const &data)
return;
}
+ gsize bytes_written;
GOutputStream *ostream = g_io_stream_get_output_stream (G_IO_STREAM (stream));
- g_output_stream_write_all (ostream, data.data (), data.size (), NULL,
- NULL, &error);
+ if (!g_output_stream_write_all (ostream, data.data (), data.size (),
+ &bytes_written, NULL, &error))
+ {
+ g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT
+ " bytes of data were written", bytes_written, data.size ());
+ }
}
void
@@ -312,16 +317,13 @@ GIO_IOStream::insert (TagLib::ByteVector const &data,
while (g_input_stream_read_all (istream, buffer, sizeof (buffer), &r,
NULL, &error) && r > 0)
{
- gsize w;
- g_output_stream_write_all (ostream, buffer, r, &w, NULL, &error);
-
- if (w != r)
- {
- g_warning ("%s", "Unable to write all bytes");
- }
+ gsize bytes_written;
- if (error)
+ if (!g_output_stream_write_all (ostream, buffer, r, &bytes_written,
+ NULL, &error))
{
+ g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT
+ " bytes of data were written", bytes_written, r);
g_object_unref (tstr);
g_object_unref (tmp);
return;
@@ -363,20 +365,18 @@ GIO_IOStream::removeBlock (TagLib::ulong start, TagLib::ulong len)
while (g_input_stream_read_all (istream, buffer, sizeof (buffer), &r, NULL,
NULL) && r > 0)
{
- gsize w;
+ gsize bytes_written;
+
seek (start);
- g_output_stream_write_all (ostream, buffer, r, &w, NULL, NULL);
- if (w != r)
+ if (!g_output_stream_write_all (ostream, buffer, r, &bytes_written,
+ NULL, &error))
{
- g_warning ("%s", "Unable to write all bytes");
+ g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT
+ " bytes of data were written", bytes_written, r);
+ return;
}
- if (error)
- {
- return;
- }
-
start += r;
seek (start + len);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]