[m-rev.] diff: Fix use of MR_strerror.

Peter Wang novalazy at gmail.com
Thu Oct 31 18:01:42 AEDT 2019


Also, error_to_cerrno returning -1 for unknown(Err, Msg) seems like a
weird choice.

----

extras/posix/posix.strerror.m:
    Fix use of MR_strerror (it may return a pointer to a static string
    instead of modifying the provided buffer).

    Allocate string such that it will be attributed to the predicate
    when profiling memory retention.

diff --git a/extras/posix/posix.strerror.m b/extras/posix/posix.strerror.m
index a1e3ba0de..802619cd7 100644
--- a/extras/posix/posix.strerror.m
+++ b/extras/posix/posix.strerror.m
@@ -1,4 +1,4 @@
-%-------------------------------------_--------------------------------------%
+%----------------------------------------------------------------------------%
 % vim: ft=mercury ts=4 sw=4 et
 %----------------------------------------------------------------------------%
 % Copyright (C) 2019 The Mercury team.
@@ -30,12 +30,12 @@ strerror(Err, Msg, !IO) :-
 
 :- pred strerror0(int::in, string::out, io::di, io::uo) is det.
 :- pragma foreign_proc("C",
-    strerror0(Errno::in, Txt::out, _IO1::di, _IO2::uo),
+    strerror0(Errno::in, Msg::out, _IO0::di, _IO::uo),
     [promise_pure, will_not_call_mercury, thread_safe, tabled_for_io],
 "
-    char buf[200];
-    MR_strerror(Errno, buf, 200);
-    MR_make_aligned_string_copy(Txt, buf);
+    char buf[MR_STRERROR_BUF_SIZE];
+    MR_make_aligned_string_copy_msg(Msg, MR_strerror(Errno, buf, sizeof(buf)),
+        MR_ALLOC_ID);
 ").
 
 %----------------------------------------------------------------------------%
-- 
2.23.0



More information about the reviews mailing list