【问题标题】:$ symbol causes program to crash$ 符号导致程序崩溃
【发布时间】:2016-06-30 07:30:22
【问题描述】:

这是我的程序:

#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;
}

运行它会导致错误

在抛出 'std::logic_error' 的实例后调用终止 what(): basic_string::_M_construct null 无效 中止(核心转储)

但如果我从盐中删除 $ 它运行正常。

【问题讨论】:

  • 你有没有尝试阅读一些documentation of crypt
  • 首先,捕获异常。然后 - 在 crypt 的文档中,你会发现它抛出的原因。

标签: c++


【解决方案1】:

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

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

例如,您可以在 Google 上搜索“unistd crypt”。

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

【讨论】:

  • 投反对票的人,你能解释一下你的投反对票吗?我总是有兴趣了解投票者。
猜你喜欢
  • 2015-06-28
  • 1970-01-01
  • 2012-01-07
  • 2012-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多