Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vector<string>::operator[] problem in line which does not use vector<string>

75 views
Skip to first unread message

Jivanmukta

unread,
May 16, 2022, 1:17:16 PM5/16/22
to
I have the following error while debugging my C++ application in VSCode:

/usr/include/c++/9/debug/vector:427:
In function:
std::__debug::vector<_Tp, _Allocator>::reference
std::__debug::vector<_Tp,
_Allocator>::operator[](std::__debug::vector<_Tp,
_Allocator>::size_type) [with _Tp = std::__cxx11::basic_string<char>;
_Allocator = std::allocator<std::__cxx11::basic_string<char> >;
std::__debug::vector<_Tp, _Allocator>::reference =
std::__cxx11::basic_string<char>&; std::__debug::vector<_Tp,
_Allocator>::size_type = long unsigned int]

Error: attempt to subscript container with out-of-bounds index -1, but
container only holds 8 elements.

Objects involved in the operation:
sequence "this" @ 0x0x7fffffffa870 {
type = std::__debug::vector<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >;
}

Here is call stack:

libc.so.6!__GI_raise(int sig)
(/build/glibc-sMfBJT/glibc-2.31/sysdeps/unix/sysv/linux/raise.c:50)
libc.so.6!__GI_abort() (/build/glibc-sMfBJT/glibc-2.31/stdlib/abort.c:79)
libstdc++.so.6![Unknown/Just-In-Time compiled code] (Nieznane źródło:0)
std::__debug::vector<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > >
>::operator[](std::__debug::vector<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > > > * const this,
std::__debug::vector<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >::size_type __n)
(/usr/include/c++/9/debug/vector:427)
<function called from gdb> (Nieznane źródło:0)
source_file::get_next_line_with_tokenized(source_file * const this,
std::string & line, std::string & tokenized_line)
(/home/robert/Projekty/dirtyphp_cpp/src/source_file.cpp:288)
obfuscator::remember_identifiers(obfuscator * const this, std::wstring
file_path, identifiers_vector * vec_ids, bool inside_framework, bool
inside_third_party)
(/home/robert/Projekty/dirtyphp_cpp/src/obfuscator.cpp:1914)
obfuscator::perform_remember_identifiers(obfuscator * const this,
std::wstring dir)
(/home/robert/Projekty/dirtyphp_cpp/src/obfuscator.cpp:979)
obfuscator::obfuscate_application(obfuscator * const this, bool
remember_and_replace_strings)
(/home/robert/Projekty/dirtyphp_cpp/src/obfuscator.cpp:1142)
main(int argc, const char ** argv)
(/home/robert/Projekty/dirtyphp_cpp/src/dirtyphp.cpp:149)

I don't understand the problem because the problematic line 288 of
source_file.cpp does not use vector<string>:

bool source_file::get_next_line_with_tokenized(string &line, string
&tokenized_line) {
line = tokenized_line = "";
if (get_next_line(line)) { // HERE PROBLEM (LINE 288)
if (line == "") {
tokenized_line = "";
} else {
...

(get_next_line() is NOT on call stack).

Lynn McGuire

unread,
May 16, 2022, 6:31:48 PM5/16/22
to
Need way more code.

Lynn

Alf P. Steinbach

unread,
May 17, 2022, 12:06:47 AM5/17/22
to
If eyes fail, why not use an editor to search for the word "vector" in
that avalanche of diagnostics?

By the way, not what you're asking, but you can save yourself and
maintainers a lot of work by passing by reference instead of passing
pointers. It looks like you have adopted Google guidelines. They're sh*t.

Cheers,

- Alf

Jivanmukta

unread,
May 17, 2022, 1:00:40 AM5/17/22
to
W dniu 17.05.2022 o 00:31, Lynn McGuire pisze:
Here is code of get_next_line(). Variable source_lines is vector<string>
but trace "inside get_next_line" is not displayed.

bool source_file::get_next_line(string &line) { // get next source line
(only PHP code)
TRACE("inside get_next_line");
if (current_source_line_no == -1) {
if (num_source_lines == 0) {
line = "";
return false;
}
}
TRACE("before if");
if (current_source_line_no < num_source_lines - 1) {
TRACE("inside if");
current_source_line_no++;
} else {
TRACE("inside else");
line = "";
current_source_line_no = -1;
return false;
}
TRACE("after if");
assert(current_source_line_no >= 0 && current_source_line_no <
(int)source_lines.size() && current_source_line_no < num_source_lines);
line = source_lines[current_source_line_no];
start_inside_php = inside_php;
bool inside_apostr = false, inside_quotat = false;
for (size_t j = 0, len = line.length(); j < len; j++) {
if (inside_php) {
if (line.substr(j, 2) == "?>" && !inside_apostr && !inside_quotat) {
j++;
inside_php = false;
} else if (line.substr(j, 1) == "'" && !inside_quotat) {
inside_apostr = !inside_apostr;
} else if (line.substr(j, 1) == "\"" && !inside_apostr) {
inside_quotat = !inside_quotat;
}
} else { // outside PHP
if (line.substr(j, 2) == "<?" && line.substr(j + 2, 3) != "xml") {
j++;
inside_php = true;
inside_apostr = inside_quotat = false;
} else {
line[j] = ' ';
}
}
}
return true;
}

Paavo Helde

unread,
May 17, 2022, 1:44:51 AM5/17/22
to
16.05.2022 20:17 Jivanmukta kirjutas:
> I have the following error while debugging my C++ application in VSCode:
}
>
> Here is call stack:
>
> <function called from gdb> (Nieznane źródło:0)

This line suggests this is some call made from gdb, not your program.
Maybe VSCode is trying to evaluate something under your cursor (never
used VSCode so not sure what it is capable of).

Either that, or the program has corrupted its memory state so much that
the correct backtrace is lost.

Jivanmukta

unread,
May 17, 2022, 2:09:21 AM5/17/22
to
And here is code of get_next_line_with_tokenized(). Variable
tokenized_lines is vector<string>.

bool source_file::get_next_line_with_tokenized(string &line, string
&tokenized_line) {
line = tokenized_line = "";
if (get_next_line(line)) {
if (line == "") {
tokenized_line = "";
} else {
while (current_tokenized_lines_iter != tokenized_lines.end()) {
if (current_tokenized_lines_iter->first == current_source_line_no) {
tokenized_line += current_tokenized_lines_iter->second + " ";
}
if (current_tokenized_lines_iter->first > current_source_line_no) {
return true;
}
++current_tokenized_lines_iter;
}
}
return true;
} else {
tokenized_line = "";
}
return false;
}

Jivanmukta

unread,
May 17, 2022, 3:13:35 AM5/17/22
to
W dniu 17.05.2022 o 07:44, Paavo Helde pisze:
> 16.05.2022 20:17 Jivanmukta kirjutas:
>> I have the following error while debugging my C++ application in VSCode:
> }
>>
>> Here is call stack:
>>
>> <function called from gdb> (Nieznane źródło:0)
>
> This line suggests this is some call made from gdb, not your program.

Possible. The problem does not occur when compiling from command line.
But I need debugger anyway, because my program does not work correctly
and I need to make it correct.

Jivanmukta

unread,
May 17, 2022, 4:40:35 AM5/17/22
to
W dniu 17.05.2022 o 09:13, Jivanmukta pisze:
> W dniu 17.05.2022 o 07:44, Paavo Helde pisze:
>> 16.05.2022 20:17 Jivanmukta kirjutas:
>>> I have the following error while debugging my C++ application in VSCode:
>> }
>>>
>>> Here is call stack:
>>>
>>> <function called from gdb> (Nieznane źródło:0)
>>
>> This line suggests this is some call made from gdb, not your program.
>
> Possible. The problem does not occur when compiling from command line.
> But I need debugger anyway, because my program does not work correctly
> and I need to make it correct.

Reinstalling gdb and VSCode didn't help.

Jivanmukta

unread,
May 17, 2022, 9:41:50 AM5/17/22
to
W dniu 17.05.2022 o 10:40, Jivanmukta pisze:
> Reinstalling gdb and VSCode didn't help.

I changed IDE from VSCode to VSCodium. In VSCodium debugging works fine.
The problem does not occur in VSCodium.
Problem closed.

0 new messages