[glib/wip/smcv/gvariant-memcpy0: 12/12] gvariant-core: Don't pass NULL second argument to memcpy



commit e9337a9c1d3bfa5809765b498650bfa6f0121da3
Author: Simon McVittie <smcv collabora com>
Date:   Mon Nov 4 17:34:17 2019 +0000

    gvariant-core: Don't pass NULL second argument to memcpy
    
    Similar to 3837b83f, glibc memcpy is declared with the first two
    arguments annotated as non-null via an attribute, which results in the
    undefined behaviour sanitizer considering it to be UB to pass a null
    pointer there (even if we are copying no bytes, and hence not actually
    dereferencing the pointer).
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 glib/gvariant-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
index 9397573a3..f0b372f40 100644
--- a/glib/gvariant-core.c
+++ b/glib/gvariant-core.c
@@ -554,7 +554,8 @@ g_variant_new_from_bytes (const GVariantType *type,
                           aligned_size) != 0)
         g_error ("posix_memalign failed");
 
-      memcpy (aligned_data, g_bytes_get_data (bytes, NULL), aligned_size);
+      if (aligned_size != 0)
+        memcpy (aligned_data, g_bytes_get_data (bytes, NULL), aligned_size);
 
       bytes = owned_bytes = g_bytes_new_with_free_func (aligned_data,
                                                         aligned_size,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]