Creating a Leak-Free, Thread-Safe Grep Utility in C23 with Safe Programming Practices
By
mithcs
Slow-proofed and worth the wait. Worth its weight in flour.
Summary
The article details the author's experience creating a leak-free, thread-safe grep utility in C23 using a custom header file called safe_c.h. It explains how to write safer C code by avoiding common pitfalls like memory leaks, segmentation faults, and thread safety issues. The author shares practical techniques for writing robust C programs while maintaining performance, and provides insights into modern C23 features that help prevent programming errors.
Key quotes
· 3 pulledLet's be honest: most people have a love-hate relationship with C. We love its raw speed, its direct connection to the metal, and its elegant simplicity. But we hate its footguns, its dragons, the untamed beasts.
The story of how I wrote a leak-free, thread-safe grep in C23 without shooting yourself in the foot, and how you can too!
The segfaults that appear from nowhere, the memory leaks that slowly drain the life from our applications, and the endless goto cleanup;
You might also wanna read
Cscript Style Guide: A Python-Inspired Approach to C Programming
Cscript is presented as a style guide for writing C code that aims to make C development faster and more Python-like while maintaining C's p
Pigeon's Device: An Independent Loop Optimization Technique in C Programming
The article introduces Pigeon's device, a loop optimization technique in C programming that was independently developed from Duff's device.
Implementing Closures in C Using JIT-Compiled Wrappers for Win32 Window Procedures
The article discusses an advanced programming technique for creating closures in C using JIT-compiled wrappers, specifically applied to Win3
Guidelines for Writing Fully Encapsulated C Programs: Pure vs Performance Approaches
This article presents a comprehensive set of rules and guidelines for writing fully encapsulated C programs, developed by the author over ye
Checked-size Array Parameters in C: Addressing Safety Issues with Array Size Validation
The article discusses a recent attempt to add safety checks for array parameters in the C programming language, specifically within the cryp
Implementing Generic Programming in C: Techniques and Trade-offs
The article explains how to implement generic programming in C despite the language not having built-in generics support. It covers various
