【发布时间】:2020-12-16 14:26:34
【问题描述】:
据我所知,我的代码没有递归,但出现异常 0xC00000FD。根据 Rider For Unreal Engine 的说法,它发生在 main 函数中。在反编译的代码中遇到了
mov byte ptr [r11], 0x0
它工作正常,然后当我第二次运行它时,为了确保它正常工作,它突然坏了。现在它每次都会给出这个例外。 这是我的代码:
// Language.cpp
#include <fstream>
#include <iostream>
#include <regex>
#include <stdexcept>
#include <string>
#include "Lexer/Lexer.h"
#include "Util/StrUtil.h"
int main(int argc, char* argv[])
{
std::string line, fileString;
std::ifstream file;
file.open(argv[1]);
if(file.is_open())
{
int lines = 0;
while(file.good())
{
if (lines > 10000)
{
std::cerr << "Whoa there, that file's a little long! Try compiling something less than 10,000 lines." << '\n';
return -1;
}
getline(file, line);
fileString += line + (char)10;
lines++;
}
}
fileString += (char)0x00;
std::string arr[10000];
int arrLength = StrUtil::split(fileString, "\n", arr);
Line lines[10000];
Lexer::lex(arr, arrLength, lines);
return 0;
}
// Lexer.cpp
#include "Lexer.h"
void Lexer::lex(std::string (&str)[10000], int length, Line (&lines)[10000])
{
for (int i = 0; i < length; i++)
{
}
}
// StrUtil.cpp
#include "StrUtil.h"
#include <stdexcept>
#include <string>
int StrUtil::split(std::string str, std::string delimiter, std::string (&out)[10000])
{
int pos = 0;
out[0] = str;
while (out[pos].find(delimiter) != std::string::npos)
{
const size_t found = out[pos].find(delimiter);
out[pos + 1] = out[pos].substr(found + delimiter.length());
out[pos] = out[pos].substr(0, found);
pos++;
}
return pos + 2;
}
对于自定义类型,Line 是 Tokens 的数组,它们只是 TokenType, std::string> 对。
【问题讨论】:
-
std::string arr[10000];Line lines[10000];-- 堆栈爆炸了。 -
@PaulMcKenzie 你的意思是内存不足吗?
-
@LysanderMealy 除了堆栈内存不足之外,什么是堆栈溢出?
-
@LysanderMealy 我想是时候学习使用
std::vector了, -
顺便提一下,
(char)0x00通常写成'\0'。而(char)10是不寻常的;如果应该插入换行符,请将其写为'\n'。