-fbounds-safety: Enforcing bounds safety for C
41–50 of 129 posts
Re: -fbounds-safety: Enforcing bounds safety for C
#42template 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.
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 ri…
Re: -fbounds-safety: Enforcing bounds safety for C
#43Earlier quoted context omitted.
What are you hoping it will achieve?
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.
Re: -fbounds-safety: Enforcing bounds safety for C
#44Re: -fbounds-safety: Enforcing bounds safety for C
#45[dead]
Re: -fbounds-safety: Enforcing bounds safety for C
#46Re: -fbounds-safety: Enforcing bounds safety for C
#47template 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.
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
Re: -fbounds-safety: Enforcing bounds safety for C
#48I 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.
Maybe this: https://fil-c.org/pizlix >Pizlix is LFS (Linux From Scratch) 12.2 with some added components, where userland is compiled with Fil-C. This means you get the most memory safe Linux-like OS currently available. The author, @pizlonator, is active on HN.
Re: -fbounds-safety: Enforcing bounds safety for C
#49Re: -fbounds-safety: Enforcing bounds safety for C
#50[dead]
You have to instrument every single file. It can be done in stages though. Just turn the flag on one-by-one for each file. The xnu kernel is _mostly_ instrumented with -fbounds-safety.