Skip to content

Commit bc7be0d

Browse files
ci(lint markdown): Lint your markdown using rumdl
Also added getting started safety and why-nextstd stuff Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>
1 parent 234df68 commit bc7be0d

9 files changed

Lines changed: 227 additions & 6 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Markdown Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
rumdl-check:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v6
14+
- uses: rvben/rumdl@v0
15+
with:
16+
path: src

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
1-
# Documentation
1+
# Introduction to NextStd
22

3-
This is the Documentation repo for [NextStd](https://github.com/NextStd)
3+
Welcome to the official documentation for **NextStd**—the safer,
4+
modern alternative to the traditional C standard library.
5+
6+
For decades, C developers have relied on `<stdio.h>`, `<string.h>`,
7+
and `<stdlib.h>`. While incredibly fast, these legacy libraries are
8+
fundamentally unsafe. A single mismatched `%d` in a `printf`, a missing
9+
`\0` in a string, or a silent `NULL` pointer can trigger catastrophic
10+
Segmentation Faults, buffer overflows, and security vulnerabilities.
11+
12+
NextStd fixes this at the foundation.
13+
14+
By combining the elegant simplicity of C11 macros on the
15+
frontend with the mathematically proven memory safety of Rust
16+
on the backend, NextStd delivers a zero-compromise development experience.
17+
18+
## Core Pillars of NextStd
19+
20+
* **Type-Safe I/O:** Never write a format specifier again. NextStd uses C11
21+
`_Generic` macros to automatically route data types at compile time.
22+
* **Crash-Proof Control Flow:** Replace silent failures and dangerous `goto`
23+
statements with Python-style `NS_TRY` and `NS_EXCEPT` macros.
24+
* **Immunity to NULL:** Every FFI boundary rigorously checks for `NULL`
25+
pointers. Passing bad memory to NextStd gracefully returns an error
26+
code instead of killing your program.
27+
* **Modern String Memory:** Strings are powered by Small String Optimization
28+
(SSO), meaning short text costs zero heap allocations, and massive text safely
29+
catches Out-Of-Memory (OOM) errors without panicking.
30+
31+
### Who is this for?
32+
33+
NextStd is built for C developers, systems programmers, and embedded engineers
34+
who want the safety guarantees of a modern language without actually having to
35+
rewrite their entire codebase in Rust. It compiles down to a standard static or
36+
dynamic C library (`.a`, `.so`, `.dylib`, or `.dll`) and links identically t
37+
o any standard C dependency.
438

5-
The documentation is created using `mdbook`

rumdl.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[MD013]
2+
line-length = 80
3+
reflow = true

src/README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,45 @@
1-
# Introduction
1+
# Introduction to NextStd
2+
3+
Welcome to the official documentation for **NextStd**—the safer,
4+
modern alternative to the traditional C standard library.
5+
6+
For decades, C developers have relied on `<stdio.h>`, `<string.h>`,
7+
and `<stdlib.h>`. While incredibly fast, these legacy libraries are
8+
fundamentally unsafe. A single mismatched `%d` in a `printf`, a missing
9+
`\0` in a string, or a silent `NULL` pointer can trigger catastrophic
10+
Segmentation Faults, buffer overflows, and security vulnerabilities.
11+
12+
NextStd fixes this at the foundation.
13+
14+
By combining the elegant simplicity of C11 macros on the
15+
frontend with the mathematically proven memory safety of Rust
16+
on the backend, NextStd delivers a zero-compromise development experience.
17+
18+
## Core Pillars of NextStd
19+
20+
* **Type-Safe I/O:** Never write a format specifier again. NextStd uses C11
21+
`_Generic` macros to automatically route data types at compile time.
22+
* **Crash-Proof Control Flow:** Replace silent failures and dangerous `goto`
23+
statements with Python-style `NS_TRY` and `NS_EXCEPT` macros.
24+
* **Immunity to NULL:** Every FFI boundary rigorously checks for `NULL`
25+
pointers. Passing bad memory to NextStd gracefully returns an error
26+
code instead of killing your program.
27+
* **Modern String Memory:** Strings are powered by Small String Optimization
28+
(SSO), meaning short text costs zero heap allocations, and massive text safely
29+
catches Out-Of-Memory (OOM) errors without panicking.
30+
31+
### Who is this for?
32+
33+
NextStd is built for C developers, systems programmers, and embedded engineers
34+
who want the safety guarantees of a modern language without actually having to
35+
rewrite their entire codebase in Rust. It compiles down to a standard static or
36+
dynamic C library (`.a`, `.so`, `.dylib`, or `.dll`) and links identically t
37+
o any standard C dependency.
38+
39+
### Ready to upgrade your C code?
40+
41+
Navigate through this book using the sidebar to the left. We recommend starting
42+
with **[Why NextStd?](intro/why-nextstd.md)** for a deeper dive into the
43+
architectural philosophy, or jumping straight into
44+
**[Getting Started](getting-started/getting-started.md)** to write your first
45+
safe program!

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- [Why NextStd?](intro/why-nextstd.md)
55
- [Safety Guarantees](intro/safety.md)
66

7-
- [Getting Started](getting-started/README.md)
7+
- [Getting Started](getting-started/getting-started.md)
88
- [Installation & Linking](getting-started/installation.md)
99
- [Your First Program](getting-started/hello-world.md)
1010
- [Build System Integration](getting-started/build-systems.md)

src/getting-started/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/getting-started/getting-started.md

Whitespace-only changes.

src/intro/safety.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,62 @@
11
# Safety Guarantees
2+
3+
When we say NextStd is "safe," we aren't just talking about compiler warnings or
4+
best practices. We are talking about architectural guarantees enforced at the
5+
Foreign Function Interface (FFI) boundary between C and Rust.
6+
7+
Here are the core vulnerability classes that NextStd entirely eliminates from
8+
your C codebase.
9+
10+
## 1. Null Pointer Immunity (No More Segfaults)
11+
12+
In standard C, passing a `NULL` pointer to `strlen()` or `strcpy()` results in
13+
immediate Undefined Behavior, typically manifesting as a fatal Segmentation
14+
Fault.
15+
16+
NextStd actively intercepts bad memory. Every single FFI boundary function in
17+
the library checks for `NULL` before performing any operations. If a `NULL`
18+
pointer is detected, the operation is safely aborted, and an `NS_ERROR_ANY` code
19+
is returned for your `NS_TRY` block to catch gracefully.
20+
21+
## 2. Out-of-Memory (OOM) Protection
22+
23+
Standard C's `malloc` returns `NULL` when the heap is exhausted—a condition
24+
developers frequently forget to check. Standard Rust, on the other hand, will
25+
panic and instantly crash the program when an allocation fails.
26+
27+
NextStd takes the safe middle path. It uses Rust's `try_reserve` API for all
28+
dynamic heap allocations. If the system runs out of memory (a critical threat in
29+
embedded and constrained environments), NextStd safely catches the failure and
30+
returns an `NS_ERROR_STRING_ALLOC` code without crashing your process.
31+
32+
## 3. Buffer Overflow Prevention
33+
34+
C strings are notoriously dangerous null-terminated (`\0`) arrays. If you forget
35+
the terminator, or use `strcat` into a buffer that is even one byte too small,
36+
you silently overwrite adjacent memory.
37+
38+
NextStd uses a length-prefixed struct combined with Small String Optimization
39+
(SSO). The exact length of the string is always known. If a string needs to grow
40+
beyond its 24-byte inline capacity, NextStd automatically and safely requests
41+
exactly the right amount of heap memory. Buffer overflows are mathematically
42+
impossible by design.
43+
44+
## 4. Format String Vulnerabilities
45+
46+
Using `printf("%d", "text")` forces the C compiler to trust the developer
47+
blindly. If the format specifier doesn't match the variable type, the program
48+
reads garbage memory from the stack or crashes entirely.
49+
50+
NextStd leverages C11 `_Generic` macros to completely eliminate this class of
51+
bugs by routing types at compile time:
52+
53+
```c
54+
int age = 21;
55+
ns_string name; // Assume initialized
56+
57+
ns_println(age); // Automatically routes to ns_print_int
58+
ns_println(name); // Automatically routes to ns_print_string
59+
```
60+
61+
Because there are no format strings, format string vulnerabilities simply cannot
62+
exist.

src/intro/why-nextstd.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,66 @@
11
# Why NextStd?
2+
3+
C is the undisputed language of the physical and systems world.
4+
Whether you are building real-time camera processing pipelines,
5+
writing constrained firmware for microcontrollers like the ESP32
6+
and RP2040, or crafting lightning-fast terminal applications, C gives
7+
you the raw, uncompromised control you need.
8+
9+
But that control comes with a massive, decades-old hidden cost:
10+
**The Standard Library.**
11+
12+
## The Legacy C Trap
13+
14+
Libraries like `<stdio.h>`, `<string.h>`, and `<stdlib.h>` were designed
15+
in an era before cybersecurity was a primary concern. Today, they are
16+
the root cause of the majority of software vulnerabilities.
17+
18+
Consider a standard C input operation:
19+
20+
```c
21+
int age;
22+
printf("Enter your age: ");
23+
scanf("%d", &age);
24+
```
25+
26+
If a user types `"twenty"` instead of `20`, `scanf` silently fails,
27+
leaves the invalid text in the input buffer (corrupting future reads),
28+
and leaves `age` uninitialized. If you try to concatenate two strings using
29+
`strcat` and miscalculate the buffer size by a single byte, you trigger a
30+
buffer overflow. If you pass a `NULL` pointer into `strlen`, your entire
31+
system crashes with a Segmentation Fault.
32+
33+
In mission-critical environments, a single uncaught `NULL` pointer can brick a
34+
device or crash a production system.
35+
36+
### The Rewrite Dilemma
37+
38+
The modern industry answer to C's unsafety is to rewrite everything in Rust.
39+
40+
Rust is incredible. It mathematically proves memory safety at compile time.
41+
However, rewriting massive, established C codebases, or trying to interface
42+
Rust with highly specific hardware vendor SDKs, is often unrealistic, expensive,
43+
and time-consuming.
44+
45+
Developers shouldn't have to abandon their C codebases just to get modern safety
46+
guarantees.
47+
48+
## The NextStd Bridge
49+
50+
**NextStd** was built to be the bridge. It is a drop-in systems library that
51+
brings the fearless safety of Rust directly into C, using standard Foreign
52+
Function Interface (FFI) boundaries.
53+
54+
With NextStd, you don't rewrite your C code; you just upgrade your tools.
55+
56+
* **You keep** your C compiler, your Makefiles, and your existing architecture.
57+
* **You replace** dangerous functions like `printf` and `scanf` with
58+
`ns_print` and `ns_read`.
59+
* **You gain** compile-time type routing, `NULL` pointer immunity,
60+
safe heap allocation, and Python-style `TRY/EXCEPT` error handling.
61+
62+
By handling the most dangerous operations (I/O, string manipulation,
63+
and dynamic memory) in a memory-safe backend, NextStd allows you to write
64+
C code that is fundamentally immune to standard library footguns.
65+
66+
You get the speed of C, with the peace of mind of Rust.

0 commit comments

Comments
 (0)