XGetWindow属性 的 Window 类型的正确大小

Correct size of Window type for XGetWindowProperty

我正在使用此代码从根 window 读取 _NET_ACTIVE_WINDOW 原子:

Atom actualType;
int actualFormat;
unsigned long nItems, bytesAfter;
unsigned char * value;

if (XGetWindowProperty(display, window, atom, 0, LONG_MAX / 4,
                       False, XA_WINDOW,
                       &actualType, &actualFormat,
                       &nItems, &bytesAfter, &value) != Success ||
    actualType != XA_WINDOW) {
    return NULL;
}

Window result = *(Window*)value;    /*  <=== this line seems dubious */
XFree(value);
return result;

然而,尽管它有效,但我很确定它有问题,因为添加一些 printfs 表明:

因此,根据文档,为 属性 分配的缓冲区长度为 4 个字节。从中读取 Window 是明显的溢出。

那有什么关系呢?是否有一些我想念的标志使 Window 只有 4 个字节?我应该将值作为 uint32_t 读取并在之后将其转换为 Window 吗?还有什么吗?

文档 (XGetWindowProperty(3)) 指出:

If the specified format is 32, the property data must be a long array.

包含文件将 Window 显示为 XID 的类型定义,这是 unsigned long.

的类型定义

我猜 32 的使用是不合时宜的,过去表示 32 位,但现在表示您的编译器选择用于 unsigned long.

的任何内容