frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

-fbounds-safety: Enforcing bounds safety for C

https://clang.llvm.org/docs/BoundsSafety.html
45•thefilmore•3d ago

Comments

musicale•1d ago
I want an OS distro where all C code is compiled this way.

OpenBSD maybe? or a fork of CheriBSD?

macOS clang has supported -fbounds-safety for a while, but I"m not sure how extensively it is used.

1over137•1h ago
>I want an OS distro where all C code is compiled this way.

You first have to modify "all C code". It's not just a set and forget compiler flag.

wyldfire•1h ago
You need to annotate your program with indications of what variable tracks the size of the allocation. So, sure, but first work on the packages in the distro.

Note that corresponding checks for C++ library containers can be enabled without modifying the source. Google measured some very small overhead (< 0.5% IIRC) so they turned it on in production. But I'd expect an OS distro to be mostly C.

[1] https://libcxx.llvm.org/Hardening.html

bombcar•1h ago
Get gentoo, add this to CFLAGS and start fixing everything that breaks. Become a hero.
pezgrande•1h ago
does any distro uses clang? I thought all linux kernels were compiled using gcc.
zmodem•45m ago
Not a Linux distro, but FreeBSD uses Clang.

And Android uses Clang for its Linux kernel.

-fbounds-safety is not yet available in upstream Clang though:

> NOTE: This is a design document and the feature is not available for users yet.

honktime•1m ago
Chimera does, it also has a FreeBSD userland AFAIU.

https://chimera-linux.org/

pjmlp•1h ago
It is called Solaris, and has this enabled since 2015 on SPARC.

https://docs.oracle.com/en/operating-systems/solaris/oracle-...

prussian•1h ago
Fedora and its kernels are built with GCC's _FORTIFY_SOURCE and I've seen modules crash for out of bounds reads.
dezgeg•40m ago
_FORTIFY_SOURCE is way smaller in scope (as in, closes less vulnerabilities) than -fbounds-safety.
groundzeros2015•26m ago
What are you hoping it will achieve?
irishcoffee•21m ago
The internet went down because cloudflare used a bad config... a config parsed by a rust app.

One of these days the witch hunt against C will go away.

random_mutex•8m ago
A panic in Rust is easier to diagnose and fix than some error or grabage data that was caused by an out of bounds access in some random place in the call stack
nananana9•1h ago

  template <typename T>
  struct Slice {
      T* data = nullptr;
      size_t size = nullptr;

      T& operator[](size_t index) {
        if (index >= size) crash_the_program();
        return data[index];
      }
  };

If you're considering this extension, just use C++ and 5 lines of standard, portable, no-weird-annotations code instead.
baq•1h ago
and if you write directly in assembly you don't even need a C++ compiler
nananana9•1h ago
That's an objectively correct statement, but I don't see how it makes sense as a response to my comment, as I'm advocating to use the more advanced feature-rich tool over the compiler-specific-hacks one.
zephen•32m ago
> I don't see how it makes sense as a response to my comment

Your comment started out with "just."

As if there are never any compelling reasons to want to make existing C code better.

But instead of taking that as an opportunity to reflect on when various tools might be appropriate,

> as I'm advocating to use the more advanced feature-rich tool over the compiler-specific-hacks one.

You've simply doubled down.

pjmlp•1h ago
Even better, starting with C++26, and considered to be done with DR for previous versions, hardned runtimes now have a portable way to be configured across compilers, instead of each having their own approach.

However, you still need something like -fbounds-safety in C++, due to the copy-paste compatibility with C, and too many people writing Orthodox C++, C with Classes, Better C, kind of code, that we cannot get rid of.

nananana9•1h ago
I'm sure std::span is great, but I like mine better :)

I find it a bit hard to justify using the STL when a single <unordered_map> include costs 250ms compile time per compile unit.

The fact that I don't have to step through this in the debugger is also a bonus:

  template <size_t _Offset, size_t _Count = dynamic_extent>
  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto subspan() const noexcept
      -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset> {
    static_assert(_Offset <= _Extent, "span<T, N>::subspan<Offset, Count>(): Offset out of range");
    static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset,
                  "span<T, N>::subspan<Offset, Count>(): Offset + Count out of range");

    using _ReturnType = span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>;
    return _ReturnType{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
  }
pjmlp•36m ago
Only if not able to do import std, or pre-compiled headers, and not using modern IDEs with "just my code" filters.

As someone that enjoys C++ since 1993, alongside other ecosystems, many pain points on using C++ complaints are self inflicted, by avoiding using modern tools.

Heck, C++ had nice .NET and Java alike frameworks, with bounds checking even, before those two systems came to exist, and nowadays all those frameworks are mostly gone with exception of Qt and C++ Builder ones, due to bias.

zmodem•52m ago
The extension is for hardening legacy C code without breaking ABI.
wat10000•52m ago
You should tell the LLVM folks, I guess they didn't know about this.
uecker•49m ago
Or just do it in C.

  #define span(T) struct span_##T { size_t len; T *data; }
  #define span_access(T, x, i) (*({              \
    span(T) *_v = (x);                           \
    auto _i = (i);                               \
    if (((size_t)_i) >= _v->len) abort();        \
    &_v->data[_i];                               \
  }))
https://godbolt.org/z/TvxseshGc
nananana9•8m ago
Still requires a gcc/clang specific extension (although this one I'd be very happy to see standardized)
taminka•23m ago
this is amazing, counter to what most ppl think, majority of memory bugs are from out of bounds access, not stuff like forgetting to free a pointer or some such
Retr0id•19m ago
I think UAFs are more common in mature software
q3k•10m ago
Or type confusion bugs, or any other stuff that stems from complex logic having complex bugs.

Boundary checking for array indexing is table stakes.

random_mutex•14m ago
There is use after free
eecc•10m ago
Majority. Parent said majority
worldsavior•19m ago
Very cool. I always wondered why there isn't something like this in GCC/LLVM, it would obviously solve uncountable of security issues.
ndiddy•8m ago
Has any progress been made on this? I remember seeing this proposal 3 or 4 years ago but it looks like it still hasn't been implemented. It's a shame because it seems like a useful feature. It looks like Microsoft has something similar (https://learn.microsoft.com/en-us/cpp/code-quality/understan...) but it would be nice to have something that worked on other platforms.

America vs. Singapore: You Can't Save Your Way Out of Economic Shocks

https://www.governance.fyi/p/america-vs-singapore-you-cant-save
39•guardianbob•54m ago•10 comments

Pebble Production: February Update

https://repebble.com/blog/february-pebble-production-and-software-updates
123•smig0•3h ago•41 comments

Don't Trust the Salt: AI Summarization, Multilingual Safety, and LLM Guardrails

https://royapakzad.substack.com/p/multilingual-llm-evaluation-to-guardrails
124•benbreen•2d ago•44 comments

Paged Out Issue #8 [pdf]

https://pagedout.institute/download/PagedOut_008.pdf
93•SteveHawk27•3h ago•13 comments

-fbounds-safety: Enforcing bounds safety for C

https://clang.llvm.org/docs/BoundsSafety.html
46•thefilmore•3d ago•31 comments

Show HN: Mini-Diarium - An encrypted, local, cross-platform journaling app

https://github.com/fjrevoredo/mini-diarium
68•holyknight•3h ago•39 comments

Bridging Elixir and Python with Oban

https://oban.pro/articles/bridging-with-oban
63•sorentwo•4h ago•19 comments

Coding Tricks Used in the C64 Game Seawolves

https://kodiak64.co.uk/blog/seawolves-technical-tricks
39•atan2•3h ago•3 comments

Show HN: A physically-based GPU ray tracer written in Julia

https://makie.org/website/blogposts/raytracing/
72•simondanisch•4h ago•30 comments

The Mongol Khans of Medieval France

https://www.historytoday.com/archive/feature/mongol-khans-medieval-france
66•Thevet•2d ago•17 comments

Sizing chaos

https://pudding.cool/2026/02/womens-sizing/
707•zdw•18h ago•378 comments

Famous Signatures Through History

https://signatory.app/#famous-signatures
20•elliotbnvl•1h ago•20 comments

Large Language Models for Mortals: A Practical Guide for Analysts with Python

https://crimede-coder.com/blogposts/2026/LLMsForMortals
12•apwheele•4d ago•1 comments

Against Theory-Motivated Experimentation

https://journals.sagepub.com/doi/10.1177/26339137261421577
6•paraschopra•1h ago•2 comments

27-year-old Apple iBooks can connect to Wi-Fi and download official updates

https://old.reddit.com/r/MacOS/comments/1r8900z/macos_which_officially_supports_27_year_old/
405•surprisetalk•18h ago•229 comments

Voith Schneider Propeller

https://en.wikipedia.org/wiki/Voith_Schneider_Propeller
59•Luc•3d ago•14 comments

15 years of FP64 segmentation, and why the Blackwell Ultra breaks the pattern

https://nicolasdickenmann.com/blog/the-great-fp64-divide.html
162•fp64enjoyer•14h ago•57 comments

Old School Visual Effects: The Cloud Tank (2010)

http://singlemindedmovieblog.blogspot.com/2010/04/old-school-effects-cloud-tank.html
59•exvi•9h ago•7 comments

Cosmologically Unique IDs

https://jasonfantl.com/posts/Universal-Unique-IDs/
436•jfantl•21h ago•137 comments

Step 3.5 Flash – Open-source foundation model, supports deep reasoning at speed

https://static.stepfun.com/blog/step-3.5-flash/
157•kristianp•13h ago•62 comments

Tailscale Peer Relays is now generally available

https://tailscale.com/blog/peer-relays-ga
443•sz4kerto•23h ago•216 comments

ShannonMax: A Library to Optimize Emacs Keybindings with Information Theory

https://github.com/sstraust/shannonmax
27•sammy0910•4h ago•5 comments

Anthropic officially bans using subscription auth for third party use

https://code.claude.com/docs/en/legal-and-compliance
517•theahura•12h ago•630 comments

A word processor from 1990s for Atari ST/TOS is still supported by enthusiasts

https://tempus-word.de/en/index
85•muzzy19•2d ago•41 comments

DOGE Track

https://dogetrack.info/
198•donohoe•3h ago•94 comments

Zero-day CSS: CVE-2026-2441 exists in the wild

https://chromereleases.googleblog.com/2026/02/stable-channel-update-for-desktop_13.html
359•idoxer•23h ago•205 comments

C++26: Std:Is_within_lifetime

https://www.sandordargo.com/blog/2026/02/18/cpp26-std_is_within_lifetime
38•ibobev•1h ago•48 comments

How to choose between Hindley-Milner and bidirectional typing

https://thunderseethe.dev/posts/how-to-choose-between-hm-and-bidir/
122•thunderseethe•3d ago•43 comments

Virgins, Unicorns and Medieval Literature (2017)

https://www.bowdoin.edu/news/2017/11/virgins-unicorns-and-medieval-literature.html
9•mooreds•2d ago•5 comments

DNS-Persist-01: A New Model for DNS-Based Challenge Validation

https://letsencrypt.org/2026/02/18/dns-persist-01.html
302•todsacerdoti•21h ago•134 comments