microsoft / microsoft/vscode-cpptools

Array size error when using 2+ variable length arrays

Open
#4,984 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

debugger more info needed
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Type: Debugger

  • OS and Version: Ubuntu 18.04.4
  • VS Code Version: 1.42.1
  • C/C++ Extension Version: 0.26.3

Steps to Reproduce:

Compile the following code with clang-9 -g test.c then set a breakpoint on line 10. array1 will use whatever size array 2 has. If array 2 is larger you can access/change out of bounds memory. I was not able to reproduce the error using lldb-9 and lldb-mi-9

int testArray(int s) {
    int array1[s];
    int array2[s>>1];
    int i;
    for (i = 0; i < s; ++i)
        array1[i] = s-i;

    for (i = 0; i < 2; ++i)
        array2[i] = 100+i;
    return 0;
}

int main(){
    testArray(5);
    return 0;
}

Heres my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "clang++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "/run/user/1000/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "miDebuggerPath": "/usr/bin/lldb-mi-9"
        }
    ]
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with the supplied C program, clang-9, and launch.json, then compare the debugger's handling with lldb-9 and lldb-mi-9. Trace the C/C++ extension's variable-length-array inspection path; done means array1 and array2 retain their distinct sizes and bounds while stopped at the breakpoint.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, typescript, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.