+/* Return a pointer to data in a code blob, with bounds checking. */ +static const void *get_data_ptr(const struct vkd3d_shader_code *code, + uint32_t offset, uint32_t count, uint32_t size) +{ + if (!require_space(offset, count, size, code->size)) + { + ERR("Offset %#x and size %#x exceeds section size %#zx.\n", offset, size, code->size); + return NULL; + } + + return (const char *)code->code + offset; +}
In principle that's an issue with the input data, not the implementation. So WARN instead of ERR, I'd argue.
I have a slight preference for uint8_t over char when referring to byte arrays instead of strings.
+static HRESULT get_string(const struct vkd3d_shader_code *code, uint32_t offset, char **ret) +{ + const char *str; + char *end; + + if (offset >= code->size) + { + ERR("Offset %#x exceeds size %#zx.\n", offset, code->size); + return E_INVALIDARG; + } + + str = (const char *)code->code + offset; + if (!(end = memchr(str, 0, code->size - offset))) + { + ERR("String at %#x is not properly zero-terminated.\n", offset); + return E_INVALIDARG; + } + + if (!(*ret = vkd3d_memdup(str, end + 1 - str))) + return E_OUTOFMEMORY; + return S_OK; +}
Likewise for the ERRs here.
Just a thought, but could we get shader runner support for reflection tests?