Итератор Dereference, а затем итерация по сравнению с Derefercenced Calue [Duplicate]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Итератор Dereference, а затем итерация по сравнению с Derefercenced Calue [Duplicate]

Сообщение Anonymous »

У меня есть кусок текста с разделителями в нем. Мне нужно извлечь из него слова и преобразовать их в нижний чехол. Мой подход состоит в том, чтобы использовать регулярные выражения для разделения текста и использования Transform для преобразования в более низкий случай. Код довольно простой: < /p>
string paragraph = "some random text";

string pattern = "[\"!?',;.\"]+";
regex re(pattern); // Compile the regular expression

// std::sregex_token_iterator iterates over the non-matching parts (tokens)
// -1 indicates to return the non-matching parts
sregex_token_iterator first(paragraph.begin(), paragraph.end(), re, -1), last;

for (; first != last; first++) {
string word = *first, lowerCaseWord;
auto lowerCaseWordIt = lowerCaseWord.begin();
transform(word.begin(), word.end(), lowerCaseWordIt,
[](unsigned char c){ return tolower(c); });
cout
Line 23: Char 13:
=================================================================
==22==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ff5cb200b70 at pc 0x55e6eb28065f bp 0x7ffcadcff310 sp 0x7ffcadcff308
WRITE of size 1 at 0x7ff5cb200b70 thread T0
#0 0x55e6eb28065e in __gnu_cxx::__normal_iterator std::transform(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, Solution::mostCommonWord(std::__cxx11::basic_string, std::vector&)::'lambda'(unsigned char)) /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/stl_algo.h:4219:12
#1 0x55e6eb27f7bf in Solution::mostCommonWord(std::__cxx11::basic_string, std::vector&) solution.cpp:23:13
#2 0x55e6eb27edc0 in __DriverSolution__::__helper__(std::__cxx11::basic_string, std::vector&) solution.cpp:23:31
#3 0x55e6eb27e4ba in main solution.cpp:23:43
#4 0x7ff5ccb471c9 (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
#5 0x7ff5ccb4728a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
#6 0x55e6eb1a7ea4 in _start (solution+0xcaea4)
Address 0x7ff5cb200b70 is located in stack of thread T0 at offset 880 in frame
#0 0x55e6eb27efaf in Solution::mostCommonWord(std::__cxx11::basic_string, std::vector&) solution.cpp:23
This frame has 11 object(s):
[32, 80) 'banned_set' (line 14)
[112, 144) 'word' (line 15)
[176, 208) 'pattern' (line 19)
[240, 272) 're' (line 20)
[304, 440) 'first' (line 24)
[512, 648) 'last' (line 24)
[720, 752) 'ref.tmp104' (line 29)
[784, 816) 'word119' (line 30)
[848, 880) 'lowerCaseWord' (line 30) 0x7ff5cb200b00: f2 f2 00 00 00 00 f2 f2 f2 f2 00 00 00 00[f2]f2
0x7ff5cb200b80: f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7ff5cb200c00: 00 00 00 f2 f2 f2 f2 f2 f2 f2 f2 f2 f8 f8 f8 f8
0x7ff5cb200c80: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
0x7ff5cb200d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7ff5cb200d80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==22==ABORTING


Подробнее здесь: https://stackoverflow.com/questions/797 ... nced-value
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»