[m-rev.] for review: fix fwrite warning

Ian MacLarty maclarty at csse.unimelb.edu.au
Tue Jul 6 17:09:39 AEST 2010


For review by anyone.

hardcoded/bitmap_test passes, but I couldn't figure out how to test that
the exception is thrown when there is an error.  I thought about
changing the file permissions, but then I can't open the file for
writing.

Could someone confirm that I'm passing valid arguments to
mercury_io_error?

===================================================================

library/io.m:
    Use the return value of fwrite (called by the MR_WRITE macro)
    to avoid warnings from GCC 4.x that fwrite's return value is not
    used.

Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.433
diff -u -r1.433 io.m
--- library/io.m	7 May 2010 03:12:25 -0000	1.433
+++ library/io.m	6 Jul 2010 07:01:17 -0000
@@ -8075,7 +8075,11 @@
     [may_call_mercury, promise_pure, tabled_for_io, thread_safe, terminates,
         no_sharing],
 "
-    MR_WRITE(*Stream, Bitmap->elements + Start, Length);
+    MR_Integer bytes_written =
+        (MR_Integer)MR_WRITE(*Stream, Bitmap->elements + Start, Length);
+    if (bytes_written != Length) {
+        mercury_io_error(Stream, \"Error writing bitmap.\");
+    }
     MR_update_io(IO0, IO);
 ").
 
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list