Skip to content

fix(c): only match real atomic_* type names, not atomic functions#4446

Open
xianjianlf2 wants to merge 2 commits into
highlightjs:mainfrom
xianjianlf2:fix/c-atomic-types-3837
Open

fix(c): only match real atomic_* type names, not atomic functions#4446
xianjianlf2 wants to merge 2 commits into
highlightjs:mainfrom
xianjianlf2:fix/c-atomic-types-3837

Conversation

@xianjianlf2

Copy link
Copy Markdown
Contributor

Changes

Resolves #3837.

The C grammar's atomic_[a-z]{0,6}[kmgtptme]? wildcard rule was matching atomic function names (atomic_init, atomic_load, atomic_store, …) as types. Per the issue discussion, this replaces the wildcard with an explicit whitelist of the real <stdatomic.h> type names (atomic_bool, atomic_int, atomic_char32_t, etc.), so functions like atomic_init(...) are no longer mis-highlighted as types while all genuine atomic types keep their type scope.

New markup test test/markup/c/atomic-types covers both sides: every whitelisted type highlights as type, and atomic function calls do not.

Checklist

  • Added markup test (test/markup/c/atomic-types.txt / .expect.txt)
  • Updated CHANGES.md
  • npm run build + mocha test/markup — 546 passing

@github-actions

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +265 B

View Changes
file base pr diff
es/core.min.js 8.24 KB 8.24 KB +2 B
es/highlight.min.js 8.24 KB 8.24 KB +2 B
es/languages/c.min.js 1.97 KB 2.1 KB +129 B
highlight.min.js 8.28 KB 8.28 KB +1 B
languages/c.min.js 1.97 KB 2.1 KB +131 B

Comment thread src/languages/c.js Outdated
Comment on lines +28 to +35
'bool', 'char', 'schar', 'uchar', 'short', 'ushort', 'int', 'uint',
'long', 'ulong', 'llong', 'ullong',
'char16_t', 'char32_t', 'wchar_t',
'int_least8_t', 'uint_least8_t', 'int_least16_t', 'uint_least16_t',
'int_least32_t', 'uint_least32_t', 'int_least64_t', 'uint_least64_t',
'int_fast8_t', 'uint_fast8_t', 'int_fast16_t', 'uint_fast16_t',
'int_fast32_t', 'uint_fast32_t', 'int_fast64_t', 'uint_fast64_t',
'intptr_t', 'uintptr_t', 'size_t', 'ptrdiff_t', 'intmax_t', 'uintmax_t'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One item per line please (easier review/diffs in the future). Otherwise looks great, thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, split the atomic type list to one item per line.

@github-actions

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +257 B

View Changes
file base pr diff
es/core.min.js 8.24 KB 8.24 KB -1 B
es/highlight.min.js 8.24 KB 8.24 KB -1 B
es/languages/c.min.js 1.97 KB 2.1 KB +129 B
highlight.min.js 8.28 KB 8.28 KB -1 B
languages/c.min.js 1.97 KB 2.1 KB +131 B

The TYPE scope used a wildcard `atomic_[a-z]{3,6}` which mistakenly
highlighted C11 atomic *functions* (atomic_init, atomic_store,
atomic_load, atomic_fetch_add, ...) as types. Replace the wildcard
with an explicit whitelist of the C11 <stdatomic.h> atomic type
names so only real atomic types are highlighted.

Closes highlightjs#3837
@xianjianlf2
xianjianlf2 force-pushed the fix/c-atomic-types-3837 branch from b194618 to 0e684dd Compare July 20, 2026 06:29
@github-actions

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

4 files changed

Total change +258 B

View Changes
file base pr diff
es/core.min.js 8.24 KB 8.24 KB -1 B
es/highlight.min.js 8.24 KB 8.24 KB -1 B
es/languages/c.min.js 1.97 KB 2.1 KB +129 B
languages/c.min.js 1.97 KB 2.1 KB +131 B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(c) add whitelist for atomic_init, atomic_xyz, etc. types, not regex wildcard rule

2 participants