[Issue 24355] New: Slice copy with static arrays incorrect of bounds checking

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 25 19:43:57 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24355

          Issue ID: 24355
           Summary: Slice copy with static arrays incorrect of bounds
                    checking
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ryuukk.dev at gmail.com

## Case 1:

```
void main()
{
    char[32] id = 0;
    const(char)* str = "hello";

    id = str[0 .. 6];
}
```


id is large enough for the string "hello", it should compile instead i get:

``
Error: mismatched array lengths 32 and 6 for assignment `id[] = str[0..6]
``



## Case 2:


```
void main()
{
    char[4] id;
    id = "hello asdad";
}
```

is not not large enough, both string and array length are known at compile
time, this shouldn't compile error should be:

``
Error: mismatched array lengths 4 and 1 for assignment `id[] = "hello asdad"
``

--


More information about the Digitalmars-d-bugs mailing list