c++ - 为什么我在 solaris 上会出现这个段错误?

标签 c++ segmentation-fault solaris uuid

所以开始这段代码适用于我所有的 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/

相关文章:

python - 使用 Libclang python 绑定(bind),如何检索添加到 C++ 类/结构中的注释?

c - const struct pointer 是否保证内存损坏/崩溃问题的安全性?

linux - Solaris 平台上没有垃圾值,代码简单

c - 我的 C 应用程序中出现段错误

c++ - 我的类函数的段错误

linux - 如何在 Linux 中通过 netstat -i 获取队列字段?

linux - 如何在类似 OS 的 Solaris/Unix 中查找正常运行时间、最近一小时的平均负载

c++ - C/C++ 赋值给 std::queue<char*>

c++ - #define 语句中的预期标识符

c++ - C++ 中的运算符()