Skip to content

String literals are not constant #1869

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

Closed
HomelikeBrick42 opened this issue Jun 29, 2022 · 0 comments
Closed

String literals are not constant #1869

HomelikeBrick42 opened this issue Jun 29, 2022 · 0 comments

Comments

@HomelikeBrick42
Copy link

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Operating System & Odin Version:
  • Please paste odin report output:

Odin: dev-2022-06:173286de
OS: Windows 10 Home Basic (version: 21H2), build 19044.1766
CPU: AMD Ryzen 5 5600G with Radeon Graphics
RAM: 16176 MiB

Expected Behavior

The strings should be placed in read-only memory so trying to modify them will cause a crash

Current Behavior

They dont seem to be put in read-only memory so they can be modified and break other identical string literals in the program

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

package bug

import "core:fmt"

main :: proc() {
    foo := "hello"
    (transmute([]u8)foo)[0] = '5'
    fmt.println("hello")
}

this outputs
5ello

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