c++ - $ 符号导致程序崩溃

标签 c++

这是我的程序:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
int main()
{
    std::string hash = crypt("asd123","$2a$13$IP4FT4gf123I5bT6o4123123123123nbEXFqo.Oa123");
    std::cout << hash;
}

运行这个会导致错误

terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_M_construct null not valid Aborted (core dumped)

但是如果我从 salt 中移除 $ 它运行正常。

最佳答案

错误消息告诉您 crypt 为给定的参数返回一个空指针。这很可能是它发出失败信号的方式。您需要检查一下。

您可以通过 (1) 查找该函数的文档以及 (2) 阅读它来了解有关 crypt 的更多信息。

例如,您可以用谷歌搜索“unistd crypt”。

碰巧文档在一个漂亮的表格中指定了您可以使用的有效字符集。

关于c++ - $ 符号导致程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38116594/

相关文章:

c++ - std::vector 不使用具有 noexcept move 构造的对象调用 move 构造函数

c++ - 保留一个大数字的一部分

c++ - QGraphicsScene/View 比例理解

c++ - 在 C++ 中返回 int 进行错误检查是不是很糟糕

c++ - 在模板特化中添加单个构造函数方法

c++ - 什么是 SetupAPI、SetupAPI1 和 SetupAPI2?它们之间有什么区别?

c++ - 无法解析在 0MQ 套接字中接收到的 Jsoncpp 对象

c++ - 如何检测rgb图像格式真的是灰色的?

C++ 窗口扫描器

c++ - 协助调试 OpenGL glsl 着色器或使用它的代码