所以开始这段代码适用于我所有的 redhat 机器和一些其他的 solaris 机器。产生故障的机器是 solaris 64 位。我的代码如下:
这是 frUUID 类:
frUUID::frUUID()
{}
std::string frUUID::genUUID()
{
char uuidBuff[36];
uuid_t uuidGenerated;
uuid_generate_random(uuidGenerated);
uuid_unparse(uuidGenerated, uuidBuff);
std::cout << uuidBuff << std::endl; // prints out a correct uuid
return std::string(uuidBuff);
}
然后在单元测试中我有:
frUUID uuids;
std::string uuid1 = uuids.genUUID();
std::cout << std::endl << "UUID 1: " << uuid1 << std::endl;
//This cout produces the seg fault on the uuid1
我不知道这里发生了什么一切似乎都是正确的?有人有什么想法吗?
最佳答案
来自uuid_unparse
手册页:
The uuid_unparse function converts the supplied UUID uu from the internal binary format into a 36-byte string (plus tailing '\0')
您的缓冲区太小了。您处于未定义的行为区域。
关于c++ - 为什么我在 solaris 上会出现这个段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7066462/