[glib/ebassi/aligned-alloc] Explain the errno use in g_aligned_alloc()
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/ebassi/aligned-alloc] Explain the errno use in g_aligned_alloc()
- Date: Fri, 7 Jan 2022 17:29:25 +0000 (UTC)
commit 710a9d42c69cdc8c4130c26279329c1301d2a5da
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Jan 7 17:29:06 2022 +0000
Explain the errno use in g_aligned_alloc()
glib/gmem.c | 8 ++++++++
1 file changed, 8 insertions(+)
---
diff --git a/glib/gmem.c b/glib/gmem.c
index 4fd4250a4..ff6d33149 100644
--- a/glib/gmem.c
+++ b/glib/gmem.c
@@ -588,6 +588,14 @@ g_aligned_alloc (gsize n_blocks,
return NULL;
}
+ /* We need to clear errno because posix_memalign() will use its return
+ * value in the same way memalign() and aligned_alloc() will set errno.
+ * Additionally, posix_memalign() will warn if its return value is left
+ * unassigned.
+ *
+ * We handle all possible return values (ENOMEM and EINVAL) with either
+ * precondition or postcondition checking.
+ */
errno = 0;
#if defined(HAVE_POSIX_MEMALIGN)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]