AddressSanitizer: stack-buffer-overflow in case of string

  address-sanitizer, c++, stack-overflow, string

input -> t = "alexes"

constraints -> 1 <= t.length <= 1000

why below code throws stack-buffer-overflow error in leetcode

 bool isLongPressedName(string t) {
        cout<<" i = "<<t[800]<<endl;
        return 1;
    }

and below code do not throws any error even if both the case out of index value is printed( t.size() < 100 and t.size() < 1000 ).

 bool isLongPressedName(string t) {
        cout<<" i = "<<t[100]<<endl;
        return 1;
    }

Source: Windows Questions C++

LEAVE A COMMENT