[m-rev.] diff: fix segmentation fault in runtime on Mac OS X
Peter Wang
novalazy at gmail.com
Thu Jun 26 13:35:23 AEST 2014
On Thu, 26 Jun 2014 13:05:47 +1000 (EST), Julien Fischer <jfischer at opturion.com> wrote:
>
> Branches: master, 14.01
>
> Fix a segmentation fault in the runtime on Mac OS X.
>
> runtime/mercury_runtime_util.c:
> On Mac OS X, strerror_r also does not populate its buffer
> if it fails.
>
> Julien.
>
> diff --git a/runtime/mercury_runtime_util.c b/runtime/mercury_runtime_util.c
> index e9cfd88..8fe1fa0 100644
> --- a/runtime/mercury_runtime_util.c
> +++ b/runtime/mercury_runtime_util.c
> @@ -55,10 +55,11 @@ MR_strerror(int errnum, char *buf, size_t buflen)
> return buf;
> #elif defined(MR_HAVE_STRERROR_R)
> /*
> - ** The XSI-compliant strerror_r populates buf unless it fails.
> + ** The XSI-compliant and Mac OS X strerror_r populates buf unless it fails.
> ** The GNU-specific strerror_r does not always populate buf.
> */
> - #if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
> + #if defined(MR_MAC_OSX) || \
> + ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
> if (strerror_r(errnum, buf, buflen) != 0) {
> generic_strerror(errnum, buf, buflen);
> }
What a mess. Presumably all libraries other the glibc provide the
standard strerror_r, so the patch below should be less fragile.
Or we can try to #define the right macros so glibc always provides the
standard version.
An alternative is to check using configure but I'm afraid if the
configure test and actual compilation could differ in their flags.
Peter
diff --git a/runtime/mercury_runtime_util.c b/runtime/mercury_runtime_util.c
index 8fe1fa0..22031bc 100644
--- a/runtime/mercury_runtime_util.c
+++ b/runtime/mercury_runtime_util.c
@@ -17,6 +17,7 @@
#include "mercury_imp.h"
#include "mercury_runtime_util.h"
+#include <features.h> /* for __GNU_LIBRARY__ */
#include <stdio.h>
#ifdef MR_HAVE_UNISTD_H
@@ -58,7 +59,7 @@ MR_strerror(int errnum, char *buf, size_t buflen)
** The XSI-compliant and Mac OS X strerror_r populates buf unless it fails.
** The GNU-specific strerror_r does not always populate buf.
*/
- #if defined(MR_MAC_OSX) || \
+ #if !defined(__GNU_LIBRARY__) || \
((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
if (strerror_r(errnum, buf, buflen) != 0) {
generic_strerror(errnum, buf, buflen);
More information about the reviews
mailing list