lestrrat-go / libxml2

Interface to libxml2, with DOM interface
MIT License
230 stars 55 forks source link

Unsafe pointer usage #85

Closed asamboy2 closed 11 months ago

asamboy2 commented 1 year ago

See Golang documentation (points 1 & 2 are relevant): https://pkg.go.dev/unsafe#Pointer. The way in which you convert pointers is unsafe and Golang's race detector doesn't like it.

For example, in the file github.com/lestrrat-go/libxml2/clib/clib.go, there should be a change thats equivalent to the following for all occurences:

-       bufptr := (uintptr)(unsafe.Pointer(&buf[0]))
-       if C.MY_test_node_name((*C.xmlChar)(unsafe.Pointer(bufptr))) == 0 {
+       //bufptr := (uintptr)(unsafe.Pointer(&buf[0]))
+       if C.MY_test_node_name((*C.xmlChar)(unsafe.Pointer(&buf[0]))) == 0 {

I changed a few of them to fix my project's issue but golang's race detector only flags code paths that are run so but it might be good to audit the code base.

If you're curious, this is the function that Golang's race detector trips over: checkptrArithmetic - https://go.dev/src/runtime/checkptr.go.

github-actions[bot] commented 11 months ago

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 11 months ago

This issue was closed because it has been stalled for 7 days with no activity. This does not mean your issue is rejected, but rather it is done to hide it from the view of the maintains for the time being. Feel free to reopen if you have new comments