Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion Failure when returning pointer with ^ operator instead of & #3314

Closed
Skarsh opened this issue Mar 23, 2024 · 0 comments
Closed

Assertion Failure when returning pointer with ^ operator instead of & #3314

Skarsh opened this issue Mar 23, 2024 · 0 comments

Comments

@Skarsh
Copy link

Skarsh commented Mar 23, 2024

Context

I've been working on a simple UDP server for a game I'm making, simple repro source code is added. Running odin test . causes Assertion Failure: global_error_collector.curr_error_value_set.load() == true`.

  • Operating System & Odin Version:
  • Please paste odin report output:
    Odin: dev-2024-03:eb61cf604
    OS: Windows 11 Home Basic (version: 23H2), build 22631.3296
    CPU: 12th Gen Intel(R) Core(TM) i5-12500H
    RAM: 16109 MiB
    Backend: LLVM 17.0.1

Expected Behavior

Please describe the behavior you are expecting
Running odin test . on the provided code snippet below should cause Assertion Failure: global_error_collector.curr_error_value_set.load() == true

Current Behavior

What is the current behavior?
Running odin test . should cause Assertion Failure: global_error_collector.curr_error_value_set.load() == true

Steps to Reproduce

Small code subset that reproduces assertion trigger.
Run odin test . on this package.


import "core:encoding/endian"
import "core:fmt"
import "core:math"
import "core:net"
import "core:testing"

Server :: struct {
	max_clients:           int,
	num_connected_clients: int,
	client_connections:    [dynamic]bool,
	client_endpoints:      [dynamic]net.Endpoint,
}

get_client_endpoint :: proc(
	server: Server,
	client_idx: int,
) -> (
	^net.Endpoint,
	bool,
) {
	if (client_idx >= 0 && client_idx < len(server.client_endpoints)) {
		return ^server.client_endpoints[client_idx], true
	}
	return nil, false
}

parse_u32_from_bytes :: proc(buf: []byte) -> u32 {
	u32 := cast(^u32)(&buf[0])
	return u32^
}

@(test)
test_parse_u32_from_bytes_all_zero_bytes :: proc(t: ^testing.T) {
	buf := []byte{0, 0, 0, 0}
	u32 := parse_u32_from_bytes(buf[:])
	testing.expect(t, u32 == 0)
}

Now changing to returning &server.client_endpoints[client_idx], true instead of ^server.client_endpoints[client_idx], true does not trigger the assertion.

get_client_endpoint :: proc(
	server: Server,
	client_idx: int,
) -> (
	^net.Endpoint,
	bool,
) {
	if (client_idx >= 0 && client_idx < len(server.client_endpoints)) {
		return &server.client_endpoints[client_idx], true
	}
	return nil, false
}
dvrd pushed a commit to dvrd/Odin that referenced this issue Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant