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

[option] or block corrupts pointer #23133

Closed
russo-2025 opened this issue Dec 11, 2024 · 0 comments · Fixed by #23139
Closed

[option] or block corrupts pointer #23133

russo-2025 opened this issue Dec 11, 2024 · 0 comments · Fixed by #23139
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Option Type Bugs/feature requests, that are related to `?Type`. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@russo-2025
Copy link

russo-2025 commented Dec 11, 2024

Describe the bug

module main

struct Bar {
	name string
}
struct Foo333 {
	bars []Bar
}

fn (f Foo333) find() ?&Bar {
	bar1_2 := &f.bars[1] or { return none }
	bar1_4 := &f.bars[1]
	println("bar1_2 `${ptr_str(bar1_2)}`")
	println("bar1_4 `${ptr_str(bar1_4)}`") // ok
	
	//return &f.bars[1] //<-------- ok
	return &f.bars[1] or { return none } // wtf
}

fn main() {
	foo := Foo333{
		bars: [ Bar{name: "123"}, Bar{name: "aaa"}, Bar{name: "s34"} ]
	}

	println("o bar1 1 `${ptr_str(foo.bars[1])}`")
	println("o bar1 2 `${ptr_str(&foo.bars[1])}`")
	
	bar := foo.find() or { panic("not found") }
	println("o bar1 3 `${ptr_str(bar)}`")

	println(bar.name)
	
	bar2 := foo.find() or { panic("not found") }
	println(bar2.name)

	// v run file.v
	// o bar1 1 `1f1fd0`
	// o bar1 2 `1f1fd0`
	// bar1_2 `148fa48`
	// bar1_4 `1f1fd0`
	// o bar1 3 `148f898`
	// println(NIL)
	// bar1_2 `148fa48`
	// bar1_4 `1f1fd0`
	// aaa

	// v -prod run file.v
	// o bar1 1 `14d1fd0`
	// o bar1 2 `14d1fd0`
	// bar1_2 `145fa78`
	// bar1_4 `14d1fd0`
	// o bar1 3 `145fa48`
	//
	// bar1_2 `145fa78`
	// bar1_4 `14d1fd0`
	// println(NIL)
}

Reproduction Steps

v run file.v
v -prod run file.v

Expected Behavior

print aaa

Current Behavior

Unpredictable behavior. The code may execute correctly, crash, freeze, or produce unexpected output.

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 77e4594

Environment details (OS name and version, etc.)

V full version: V 0.4.8 a132d97.77e4594
OS: windows, �������� Windows 10 Pro v19042 64-bit
Processor: 16 cpus, 64bit, little endian,

getwd: C:\Users\russo\Desktop\vbugs
vexe: M:\_dev\vlang\v.exe
vexe mtime: 2024-12-11 14:18:59

vroot: OK, value: M:\_dev\vlang
VMODULES: OK, value: C:\Users\russo\.vmodules
VTMP: OK, value: C:\Users\russo\AppData\Local\Temp\v_0

Git version: git version 2.46.0.windows.1
Git vroot status: weekly.2024.47-142-g77e45946
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.

emcc version: Error: 'emcc' is not recognized as an internal or external command,
operable program or batch file.

thirdparty/tcc: N/A

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Huly®: V_0.6-21570

@russo-2025 russo-2025 added the Bug This tag is applied to issues which reports bugs. label Dec 11, 2024
@felipensp felipensp self-assigned this Dec 11, 2024
@felipensp felipensp added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Option Type Bugs/feature requests, that are related to `?Type`. labels Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Option Type Bugs/feature requests, that are related to `?Type`. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants