KhronosGroup / KhronosGroup/Vulkan-Docs

Prevent concatenation for string constants in headers?

Open
#2,425 2 comments 0 reactions 1 assignee View on GitHub

@oddhack is already working on this.

Since Aug 28, 2024.

Header
Dominant language
JavaScript
Stars
3.3k
Forks
549
Avg merge
5d 5h
Merged PRs (30d)
2

Description

So I've encountered the most stupid thing ever: https://infosec.exchange/@kanashimia/113033538870920565
Because string constants such as VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME are defined using preprocessor you can concatenate them accidentally.
Maybe it would be appropriate to wrap them in a parenthesis.

Quoting from the post:

GCC doesn't warn you about string concatenations at all.
Clang has -Wstring-concatenation, but that doesn't work through defines.
So IDE based on clangd won't warn about it too.

If these strings were defined in parenthesis as
# define FOO ("foo")
then such problems couldn't occur, you can't concatenate ("foo") ("bar").
Although not sure if that causes any other problems, maybe some people do rely on the ability to concatenate those strings?
Who knows.

Spec is written in a weird way where it contains quotes value=""VK_KHR_video_encode_queue"", I guess just for an easier C generation, but ideally this should be fixed just for C headers, it isn't appropriate to change the spec because of this and break other binding generators.

This is technically a breaking change at the headers API level, but do people really rely on this?
What other possible problems can wrapping string in () cause?

I just throw this out for thinking and laughs, overall the issue is minor and may be ignored, you decide.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.