ash: empty slices don't always result in null pointers
Ran into this specifically for https://docs.rs/ash/0.29.0/ash/vk/struct.PipelineMultisampleStateCreateInfoBuilder.html#method.sample_mask – if I pass a reference to an empty slice, as_ptr
doesn’t necessarily return NULL
.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15
Commits related to this issue
- generator: pSampleMask setter should write NULL if slice is empty As per [1] no explicit length field is available for `pSampleMask`, this is based on `ceil(rasterizationSamples/32)` instead. It is ... — committed to ash-rs/ash by MarijnS95 3 years ago
- Fix possible violation of spec (`pSampleMask`) I became aware of this issue through https://github.com/MaikKlein/ash/issues/256 — committed to Friz64/erupt by Friz64 3 years ago
- generator: pSampleMask setter should write NULL if slice is empty As per [1] no explicit length field is available for `pSampleMask`, this is based on `ceil(rasterizationSamples/32)` instead. It is ... — committed to ash-rs/ash by MarijnS95 3 years ago
- generator: pSampleMask setter should write NULL if slice is empty (#432) As per [1] no explicit length field is available for `pSampleMask`, this is based on `ceil(rasterizationSamples/32)` instead.... — committed to ash-rs/ash by MarijnS95 3 years ago
@coffeenotfound it is fairly trivial to adjust this function as it was already overridden. Afaik it was overridden for this reason in the first place: the length of this array is specified by a
latexmath
expression instead of a simple name of a field. This appears to be the only member affected by the null-pointer issue, everything else seems to have a separate length field (or otherwise generate to invalid Rust).Is this still an issue in practice? This case seems rare enough that it won’t hurt to have something along the lines of:
It wouldn’t be too hard to change this though since
pSampleMask
is already special-cased:https://github.com/MaikKlein/ash/blob/c7216f1c1e337f42572995c53ced178b41cf2dbe/generator/src/lib.rs#L1826-L1833
Specifically, that is appropriate if and only if there is an implicit length field and it’s correct to combine a nonzero length with a null pointer. This is very rare; the overwhelming majority of the time, either you pass a length of zero and the pointer doesn’t matter or the pointer must be nonnull.
The best solution would be taking Option<&'a [T]> where the Vulkan spec allows pointers to be null