Skip to content

Commit c92fd38

Browse files
committed
Fix dual compilation and reorder README table
- Use Module._main() directly to allow multiple compilations - Properly allocate/free argv for each compilation call - Reorder safety comparison table: Standard C → Null-Safe → bounds-safety → Rust - Fix 'Source Code' header (removed 'main.c' reference)
1 parent fd63ce8 commit c92fd38

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ Null pointer dereferences are just one category of memory safety bugs. Here's ho
3939
4040
### What Gets Fixed
4141
42-
| Safety Issue | Null-Safe Clang (null checking) | Standard C | Rust | Clang `-fbounds-safety` |
43-
|-------------|-------------|------------|------|-------------------------|
44-
| Null pointer dereferences | ✅ Fixed | ❌ Unsafe | ✅ Fixed | ❌ Unsafe |
42+
| Safety Issue | Standard C | Null-Safe Clang (null checking) | Clang `-fbounds-safety` | Rust |
43+
|-------------|------------|-------------|-------------------------|------|
44+
| Null pointer dereferences | ❌ Unsafe | ✅ Fixed | ❌ Unsafe | ✅ Fixed |
4545
| Buffer overflows | ❌ Unsafe | ❌ Unsafe | ✅ Fixed | ✅ Fixed |
46-
| Use-after-free | ❌ Unsafe | ❌ Unsafe | ✅ Fixed | ❌ Unsafe |
47-
| Double-free | ❌ Unsafe | ❌ Unsafe | ✅ Fixed | ❌ Unsafe |
48-
| Uninitialized memory | ❌ Unsafe | ❌ Unsafe | ✅ Fixed | ⚠️ Partial |
46+
| Use-after-free | ❌ Unsafe | ❌ Unsafe | ❌ Unsafe | ✅ Fixed |
47+
| Double-free | ❌ Unsafe | ❌ Unsafe | ❌ Unsafe | ✅ Fixed |
48+
| Uninitialized memory | ❌ Unsafe | ❌ Unsafe | ⚠️ Partial | ✅ Fixed |
4949
5050
5151
### Why This Still Matters

nullsafe-playground/index.html

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -997,22 +997,43 @@ <h1>Null-Safe Clang Playground</h1>
997997
captureOutput = true;
998998

999999
try {
1000-
// Use callMain if available (built with -sEXPORTED_RUNTIME_METHODS=callMain)
1001-
if (Module.callMain) {
1002-
// Build command line arguments
1003-
const args = [
1004-
'-fsyntax-only',
1005-
'--target=wasm32-unknown-emscripten',
1006-
...extraFlags,
1007-
'input.c'
1008-
];
1009-
console.log('Compiling with args:', args);
1010-
const exitCode = Module.callMain(args);
1011-
console.log('Clang exit code:', exitCode);
1012-
} else {
1013-
console.error('Module.callMain not available!');
1014-
throw new Error('Module.callMain not exported. Rebuild with -sEXPORTED_RUNTIME_METHODS=callMain');
1000+
// Build command line arguments
1001+
const args = [
1002+
'clang', // argv[0]
1003+
'-fsyntax-only',
1004+
'--target=wasm32-unknown-emscripten',
1005+
...extraFlags,
1006+
'input.c'
1007+
];
1008+
1009+
console.log('Compiling with args:', args);
1010+
1011+
// Allocate memory for argv array
1012+
const argc = args.length;
1013+
const argvPtrs = [];
1014+
1015+
// Allocate strings and collect pointers
1016+
for (let i = 0; i < argc; i++) {
1017+
const strPtr = Module.allocateUTF8(args[i]);
1018+
argvPtrs.push(strPtr);
1019+
}
1020+
1021+
// Allocate argv array
1022+
const argv = Module._malloc(argvPtrs.length * 4);
1023+
for (let i = 0; i < argvPtrs.length; i++) {
1024+
Module.HEAP32[(argv >> 2) + i] = argvPtrs[i];
10151025
}
1026+
1027+
// Call main directly
1028+
const exitCode = Module._main(argc, argv);
1029+
console.log('Clang exit code:', exitCode);
1030+
1031+
// Free allocated memory
1032+
for (let i = 0; i < argvPtrs.length; i++) {
1033+
Module._free(argvPtrs[i]);
1034+
}
1035+
Module._free(argv);
1036+
10161037
} catch (e) {
10171038
console.log('Clang execution error:', e);
10181039
}

0 commit comments

Comments
 (0)