[gjs] arg: Always zero-terminate int and float arrays



commit dc748c64e8404871f037cb545f8ee6191f29e2ba
Author: Colin Walters <walters verbum org>
Date:   Thu Jun 16 15:45:20 2011 -0400

    arg: Always zero-terminate int and float arrays
    
    Though it's weird, we want to support 0-terminated arrays of integers;
    see gi_marshalling_tests_array_in_len_zero_terminated().
    
    Do it for floats too for consistency.

 gi/arg.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/gi/arg.c b/gi/arg.c
index 5ddc709..cf20fe7 100644
--- a/gi/arg.c
+++ b/gi/arg.c
@@ -529,7 +529,8 @@ gjs_array_to_intarray(JSContext   *context,
     union { guint8 u8[0]; guint16 u16[0]; guint32 u32[0]; } *result;
     unsigned i;
 
-    result = g_malloc0(length * intsize);
+    /* add one so we're always zero terminated */
+    result = g_malloc0((length+1) * intsize);
 
     for (i = 0; i < length; ++i) {
         jsval elem;
@@ -582,7 +583,10 @@ gjs_array_to_floatarray(JSContext   *context,
                         gboolean     is_double)
 {
     unsigned int i;
-    void *result = g_malloc0(length * (is_double ? sizeof(double) : sizeof(float)));
+    void *result;
+
+    /* add one so we're always zero terminated */
+    result = g_malloc0((length+1) * (is_double ? sizeof(double) : sizeof(float)));
 
     for (i = 0; i < length; ++i) {
         jsval elem;



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