Dev-C++调用OpenSSL RAND_bytes触发STATUS_ACCESS_VIOLATION错误求助
调用OpenSSL RAND_bytes函数触发STATUS_ACCESS_VIOLATION错误
调用OpenSSL的RAND_bytes函数时,程序触发STATUS_ACCESS_VIOLATION(对应返回值3221225477),执行到该函数时直接崩溃,后续代码完全无法运行。
最小复现代码
#include <iostream> #include <openssl/rand.h> using namespace std; int main() { unsigned char buf[16] = {0}; cout << "Line1" << endl; int re = RAND_bytes(buf, sizeof(buf)); // 执行到此处程序崩溃,后续代码未执行 cout << "Line2" << endl; for (int i = 0; i < sizeof(buf); i++) cout << (int)buf[i] << " "; cout << "Line3" << endl; cout << endl; getchar(); return 0; }
已尝试的排查步骤
- 将代码放入
try...catch块中,未捕获到任何错误 - 编译无错误、无警告,调试模式下结果一致
- 尝试过其他
RAND_bytes的实现写法,问题依旧存在
环境限制与配置信息
- 无法更换编译器(学生身份,老师要求)
- 当前使用Dev-C++ 5.11、OpenSSL 3.2.0(2023年11月23日版本),多数教程针对Linux/Mac或Windows下的CodeBlocks/VS,推测是配置问题,但搜索相关关键词未找到有效解决方法
程序运行输出
Line1
Process exited after 2.541 seconds with return value 3221225477
补充细节
- 调试时显示触发SIGSEGV,与返回值对应
- 尝试移除
using namespace std语句后,问题仍然存在
内容的提问来源于stack exchange,提问作者Mark Moon
相关产品推荐
相关产品推荐

