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

[Xen-changelog] [xen master] golang/xenlight: Do proper nil / NULL conversions for builtin Bitmap type



commit 6ddfe66eb22e72391e838c88869e10c372465ae2
Author:     George Dunlap <george.dunlap@xxxxxxxxxx>
AuthorDate: Thu Dec 26 17:40:33 2019 +0000
Commit:     George Dunlap <george.dunlap@xxxxxxxxxx>
CommitDate: Tue Jan 21 17:48:23 2020 +0000

    golang/xenlight: Do proper nil / NULL conversions for builtin Bitmap type
    
    Similar to the autogenerated types, but for `builtin` Bitmap type.
    
    Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>
    Reviewed-by: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>
---
 tools/golang/xenlight/xenlight.go | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/tools/golang/xenlight/xenlight.go 
b/tools/golang/xenlight/xenlight.go
index 24b1e022ff..b1587b964f 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -396,15 +396,17 @@ type Bitmap struct {
 }
 
 func (bm *Bitmap) fromC(cbm *C.libxl_bitmap) error {
-       // Alloc a Go slice for the bytes
-       size := int(cbm.size)
-       bm.bitmap = make([]C.uint8_t, size)
+       bm.bitmap = nil
+       if size := int(cbm.size); size > 0 {
+               // Alloc a Go slice for the bytes
+               bm.bitmap = make([]C.uint8_t, size)
 
-       // Make a slice pointing to the C array
-       cs := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
+               // Make a slice pointing to the C array
+               cs := (*[1 << 
30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
 
-       // And copy the C array into the Go array
-       copy(bm.bitmap, cs)
+               // And copy the C array into the Go array
+               copy(bm.bitmap, cs)
+       }
 
        return nil
 }
@@ -412,10 +414,12 @@ func (bm *Bitmap) fromC(cbm *C.libxl_bitmap) error {
 func (bm *Bitmap) toC(cbm *C.libxl_bitmap) error {
        size := len(bm.bitmap)
        cbm.size = C.uint32_t(size)
-       cbm._map = (*C.uint8_t)(C.malloc(C.ulong(cbm.size) * C.sizeof_uint8_t))
-       cs := (*[1 << 31]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
+       if cbm.size > 0 {
+               cbm._map = (*C.uint8_t)(C.malloc(C.ulong(cbm.size) * 
C.sizeof_uint8_t))
+               cs := (*[1 << 
31]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
 
-       copy(cs, bm.bitmap)
+               copy(cs, bm.bitmap)
+       }
 
        return nil
 }
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.