Skip to content

Commit

Permalink
fix(go/adbc/drivermgr): don't call potentially nil pointer (apache#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidavidm authored Mar 4, 2024
1 parent d962961 commit bf42dc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions go/adbc/drivermgr/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ package drivermgr
// #include "adbc.h"
// #include <stdlib.h>
//
// void releaseErr(struct AdbcError* err) { err->release(err); }
// void releaseErr(struct AdbcError* err) {
// if (err->release != NULL) {
// err->release(err);
// err->release = NULL;
// }
// }
// struct ArrowArray* allocArr() {
// return (struct ArrowArray*)malloc(sizeof(struct ArrowArray));
// }
Expand Down Expand Up @@ -112,7 +117,13 @@ type Database struct {
}

func toAdbcError(code adbc.Status, e *C.struct_AdbcError) error {
err := &adbc.Error{
if e == nil || e.release == nil {
return adbc.Error{
Code: code,
Msg: "[drivermgr] nil error",
}
}
err := adbc.Error{
Code: code,
VendorCode: int32(e.vendor_code),
Msg: C.GoString(e.message),
Expand Down
4 changes: 2 additions & 2 deletions go/adbc/drivermgr/wrapper_sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func (dm *DriverMgrSuite) TestSqlExecuteInvalid() {
_, _, err = st.ExecuteQuery(dm.ctx)
dm.Require().Error(err)

var adbcErr *adbc.Error
var adbcErr adbc.Error
dm.ErrorAs(err, &adbcErr)
dm.ErrorContains(adbcErr, "[SQLite] Failed to prepare query:")
dm.ErrorContains(adbcErr, "syntax error")
Expand Down Expand Up @@ -610,7 +610,7 @@ func TestDriverMgrCustomInitFunc(t *testing.T) {
"entrypoint": "ThisSymbolDoesNotExist",
})
assert.Nil(t, db)
var exp *adbc.Error
var exp adbc.Error
assert.ErrorAs(t, err, &exp)
assert.Equal(t, adbc.StatusInternal, exp.Code)
if runtime.GOOS == "windows" {
Expand Down

0 comments on commit bf42dc6

Please sign in to comment.