Thread: [PATCH] Use DatumGetUInt32() for dsm_attach() in test_shm_mq_main()

[PATCH] Use DatumGetUInt32() for dsm_attach() in test_shm_mq_main()

From
Jianghua Yang
Date:
Hi,

The attached patch fixes a minor type mismatch in `test_shm_mq_main()`.

The argument passed to `dsm_attach()` is expected to be a `uint32`, but the
code currently uses `DatumGetInt32()` to extract it from the `Datum`
argument. This can lead to incorrect behavior when the high bit is set, as
'unable to map dynamic shared memory segment'.

This patch changes it to use `DatumGetUInt32()` to match the expected type
and ensure correctness.


Thanks,  
Jianghua Yang
Attachment
On Thu, Jun 26, 2025 at 12:51:10PM -0700, Jianghua Yang wrote:
> The argument passed to `dsm_attach()` is expected to be a `uint32`, but the
> code currently uses `DatumGetInt32()` to extract it from the `Datum`
> argument. This can lead to incorrect behavior when the high bit is set, as
> 'unable to map dynamic shared memory segment'.

I'm not sure this actually causes any problems in practice because
dsm_attach() treats its argument as unsigned.  In any case, I've never seen
this test fail like that, and presumably the high bit is sometimes set
because the handle is generated with a PRNG.

Nevertheless, I see no point in using the wrong macro.  I'll plan on
committing/back-patching this shortly.

-- 
nathan



Committed.

-- 
nathan



Hi Nathan,

Thank you for submitting this patch.

Best regards,
Jianghua


Nathan Bossart <nathandbossart@gmail.com> 于2025年6月27日周五 11:44写道:
Committed.

--
nathan