diff --git a/call_test.go b/call_test.go index 3e39ab2..52c86c2 100644 --- a/call_test.go +++ b/call_test.go @@ -186,6 +186,15 @@ func TestCallSupportsByteSliceArgument(t *testing.T) { } } +func TestCallSupportsEmptyByteSliceArgument(t *testing.T) { + t.Parallel() + + payload := []byte{} + if err := Call(callZeroByteSliceArgumentFunction(), payload); err != nil { + t.Fatalf("expected success for empty byte slice, got %v", err) + } +} + func TestErrnoMapping(t *testing.T) { t.Parallel() diff --git a/call_test_support.go b/call_test_support.go index bbf8a8f..cc46645 100644 --- a/call_test_support.go +++ b/call_test_support.go @@ -75,6 +75,10 @@ int call_buffer_argument(uintptr_t value) { return value == 0 ? 13 : 0; } +int call_zero_byte_slice_argument(uintptr_t value) { + return value == 0 ? 0 : 13; +} + int call_c_types_arguments(long a0, unsigned long a1, long long a2, unsigned long long a3) { if (a0 == 10 && a1 == 11 && a2 == 12 && a3 == 13) { return 0; @@ -130,6 +134,10 @@ uintptr_t call_buffer_argument_ptr(void) { return (uintptr_t)&call_buffer_argument; } +uintptr_t call_zero_byte_slice_argument_ptr(void) { + return (uintptr_t)&call_zero_byte_slice_argument; +} + uintptr_t call_c_types_arguments_ptr(void) { return (uintptr_t)&call_c_types_arguments; } @@ -198,6 +206,11 @@ func callBufferArgumentFunction() unsafe.Pointer { return *(*unsafe.Pointer)(unsafe.Pointer(&function)) } +func callZeroByteSliceArgumentFunction() unsafe.Pointer { + function := C.call_zero_byte_slice_argument_ptr() + return *(*unsafe.Pointer)(unsafe.Pointer(&function)) +} + func callCTypeArgumentFunction() unsafe.Pointer { function := C.call_c_types_arguments_ptr() return *(*unsafe.Pointer)(unsafe.Pointer(&function)) diff --git a/string_conversion.go b/string_conversion.go index cb97429..985045b 100644 --- a/string_conversion.go +++ b/string_conversion.go @@ -805,6 +805,11 @@ func toSyscallArg(value interface{}) (uintptr, bool) { return uintptr(typed), true case uint64: return uintptr(typed), true + case []byte: + if len(typed) == 0 { + return 0, true + } + return uintptr(unsafe.Pointer(&typed[0])), true default: reflected := reflect.ValueOf(value) switch reflected.Kind() { @@ -819,11 +824,6 @@ func toSyscallArg(value interface{}) (uintptr, bool) { return 0, true } return 0, false - case []byte: - if len(typed) == 0 { - return 0, true - } - return uintptr(unsafe.Pointer(&typed[0])), true } }