#Segmentation Fault Invalid Read of Size 8

10 messages · Page 1 of 1 (latest)

foggy vault
#

compiler is telling me that on line 183 im getting an invalid read but im not sure why any help?

lavish kayakBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

hazy copper
#

could you post the exact error message?

#

it will also be hard to troubleshoot without seeing where you define arr and how it changes throughout your code. according to google you may have used delete to free memory and now you can't access it anymore

stable elkBOT
#
How to Format Code on Discord

• type three "backticks" (not quotes/apostrophes, on QWERTY layout, left of 1-key)
• on the same line, type the file extension for that language (c or cpp)
• enter your code on a new line and put another three backticks at the end

Example Input

```cpp
int main() {
    return 0;
}
```

Example Output
int main() {
    return 0;
} ```
pale steeple
#

most likely location is an invalid index

#

so when you try to access that element, it doesn't let you and crashes

#

location needs to be strictly (not equal to) less than the size of arr

stable elkBOT
#
How To Use Sanitizers

Sanitizers are tools which generate additional code in your program that can catch many common programming mistakes, such as:
accessing arrays out of bounds
signed integer overflows
race conditions

General Advice

Not all sanitizers can be combined, but when they can, use e.g.:
-fsanitize=address,undefined to combine them. Always compile with debug info to get line numbers, variable names, etc.

GCC 4.8+

-fsanitize=address
-fsanitize=undefined
-fsanitize=thread
-g for debug info

clang 3.1+
MSVC 19.27+ and VS 2019 16.9+

-fsanitize=address
-Zi for debug info

Sample Program
int main(void) {
    int x;
    return x;
} ```
`-fsanitize=memory -g` Output

SUMMARY: MemorySanitizer: use-of-uninitialized-value /tmp/test.cpp:3:5 in main
Exiting
(3:5 is line and column of return)

lavish kayakBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.