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

[BUG] memset segmentation fault from using wrong DTypePointer type #2420

Open
dreycenfoiles opened this issue Apr 27, 2024 · 2 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers mojo Issues that are related to mojo mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library

Comments

@dreycenfoiles
Copy link

Bug description

I found that under certain conditions, using memset can cause segfaults. I don't think these edges cases are address are addressed in the docs. I get the following stack trace:

Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  mojo                               0x00005cc1afdafc87
1  mojo                               0x00005cc1afdadade
2  mojo                               0x00005cc1afdb031f
3  libc.so.6                          0x0000750081845320
4  mojo                               0x00005cc1b11ae474
5  mojo                               0x00005cc1b11ae3dc
6  mojo                               0x00005cc1b11ae31f
7  mojo                               0x00005cc1b11b9718
8  mojo                               0x00005cc1b21d05b8
9  libKGENCompilerRTShared.so.19.0git 0x000075007243b05c KGEN_CompilerRT_AlignedAlloc + 124
10 libKGENCompilerRTShared.so.19.0git 0x000075002c0011fa KGEN_CompilerRT_AlignedAlloc + 18446744072530715162
mojo crashed!
Please file a bug report.
Segmentation fault (core dumped)

Steps to reproduce

fn main():

alias dtype = DType.float64 # Won't segfault if DType.uint8

var n = 5
var vv = List[Scalar[dtype]](n)

var data = DTypePointer[dtype].alloc(n)        

memset(data, 5, n)

vv[1] = data[0] # If you index vv[0] or leave this line out, it won't segfault

print(data) # Won't segfault if you index individual members

System information

- OS: Ubuntu 24.04
- Mojo: mojo 2024.4.1618 (37a3e965)
- Modular: 0.7.2
@dreycenfoiles dreycenfoiles added bug Something isn't working mojo Issues that are related to mojo labels Apr 27, 2024
@JoeLoser JoeLoser added the mojo-stdlib Tag for issues related to standard library label Apr 29, 2024
@ematejska ematejska added the mojo-repo Tag all issues with this label label Apr 29, 2024
@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 3, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 3, 2024 — with Linear
@JoeLoser JoeLoser added the good first issue Good for newcomers label May 5, 2024 — with Linear
@soraros
Copy link
Contributor

soraros commented May 5, 2024

I don't think it has much to do with DTypePointer. vv is a list of length 1, vv[1] is UB.

@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 6, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 6, 2024 — with Linear
@LJ-9801
Copy link
Contributor

LJ-9801 commented May 14, 2024

Question about different List constructor: Should be change the constructor that takes in the size instead of the capacity? Or should we have a new constructor that takes in the size? With only the capacity user cannot access elements in the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers mojo Issues that are related to mojo mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library
Projects
None yet
Development

No branches or pull requests

5 participants