devkitPro / libctru

Homebrew development library for Nintendo 3DS/Horizon OS user mode (Arm11)

Home Page:https://libctru.devkitpro.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory access out-of-bounds while using std::cout

FurryR opened this issue · comments

commented

Example:

#include <iostream>
int main() {
  int x = 25, y = 25;
  std::cout << "\x1b[" + std::to_string(y) + ";" + std::to_string(x) + "H"; // works properly
  std::cout << "\x1b[" << y << ";" << x << "H"; // ???
}

Result:
Result
Is it "unbuffered" or something else? :/

Yes this is because iostream is effectively "unbuffered" for the standard streams. You must output the entire escape sequence in a single operation for them to work. You can try std::ios_base::sync_with_stdio(false) but I can't guarantee that the stream won't be flushed in the middle of these escape sequences. See https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio for more information.