[glib/ebassi/aligned-alloc: 3/3] Explain the errno use in g_aligned_alloc()




commit 36449ef5f969bc21d5b9900209e661354026ee99
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 67e283575..060e91af9 100644
--- a/glib/gmem.c
+++ b/glib/gmem.c
@@ -595,6 +595,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]