c++ - 获取错误调试断言失败 : Expression c >= -1 && c <= 255

标签 c++ visual-studio visual-studio-code c++14

我有以下代码在我的 ubuntu 系统上运行良好:
#include <算法>
//... 其他函数
bool IsHexPrefixed(const std::string& input) {
返回 input.substr(0, 2) == "0x";
}

std::string StripHexPrefix(const std::string& input) {
返回 IsHexPrefixed(input) 吗? input.substr(2, input.length()) :输入;
}

bool IsHexString(const std::string& input) {
std::string stripped_string_ = StripHexPrefix(input);
返回 std::all_of(stripped_string_.begin(), stripped_string_.end(),::isxdigit);
}
//... 其他一些函数

在 Windows 10 上通过 cmd , VSCode , 和 Visual Studio 2019我弹出窗口提到 Windows 和 Visual Studio 2019 上的调试断言错误。
enter image description here
出现此错误的行是 std::all_of()函数调用 IsHexString()功能。
我尝试使用异常并找出异常的来源,但还没有找到解决方案。我也尝试使用 Breakpoint 但这也无助于找到原因。
此错误的原因可能是什么?
编辑:
我传递给 IsHexString() 的字符串功能是 000002C479F17CC0 .

最佳答案

原因正是断言所说的。 isxdigit如果参数未表示为 unsigned char,则未定义或 EOF (见注释 here)。
因为它需要一个 int参数,很可能您的字符串包含范围内的字符 129-255 (可能通过包含非 ASCII 文本),因此它们被提升为负整数。
链接的 cppreference 页面还有一个解决方法,可以避免您可以应用于您的案例的促销问题:

std::all_of(stripped_string_.begin(), stripped_string_.end(),
            [](unsigned char c){ return std::isxdigit(c); });
另一种可能是StripHexPrefix函数损坏了导致上述问题的字符串。

关于c++ - 获取错误调试断言失败 : Expression c >= -1 && c <= 255,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62592717/

相关文章:

c++ - 表示同一矩阵中无向图的个数

c++ - 从这张图片中识别绿色圆圈

c++ - 为什么 auto_ptr 似乎违反了 Visual C++ 上的私有(private)继承?

c# - specflow 禁用,Specflow Package Package 没有正确加载

visual-studio-code - 如何配置 VS Code 以使用 cubeMX 构建和调试 STM32 项目 - Windows 10

visual-studio-code - 循环到 VSCode 中的先前建议

c# - 如何以编程方式查找 Windows 上的事件安全提供程序?

C++ 原子对象无锁保证

ios - 如何在 Windows 上激活 ios.windows xamarin

windows - 如何在Windows中的Visual Studio Code task.json中创建目录?