r/C_Programming • u/amondb • Jul 04 '26
Built a lightweight Integer Overflow Detector in C. Need some brutal code review!
Hi everyone,
I've recently built a lightweight tool in C to detect and mitigate Integer Overflow (CWE-190) risks.
I wanted to make something practical for secure coding practices, so I implemented safe overflow checks using `INT_MAX`, `INT_MIN`, etc.
I've also documented how to compile and run it in the README. I would deeply appreciate any code reviews, edge-case checks, or feedback on how to improve the logic!
Here is the repository: https://github.com/gimgimdongjun79-lab/Integer-Overflow-Detector
Thanks in advance!
0
Upvotes
•
u/AutoModerator Jul 04 '26
Hi /u/amondb,
Your submission in r/C_Programming was filtered because it links to a git project.
You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.
While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
9
u/mc_pm Jul 04 '26
Well that's fine and all, but this isn't really a program on it's own as much as a technique you might use. And honestly you're hyping it up just about 10x in your description of it.
5
u/sisoyeliot Jul 04 '26
It’s a good learning exercise, but not something to get hyped about that much at the point of pushing it to GH and adding a README. Create a Gist next time for this. Keep learning!
3
u/sciencekm Jul 05 '26
C23 has <stdckdint.h> with functions ckd_add, ckd_sub and ckd_mul. With compiler support, these should be optimal for the target environment.
https://en.cppreference.com/c/header/stdckdint
2
u/meancoot Jul 05 '26 •
Oops, you did the multiplication before you checked, that's too late.
https://godbolt.org/z/cYcnvEf5n
Output with
-03:Surely
0x7FFFFFFFFFFFFFFF * 0x7FFFFFFFFFFFFFFFshould overflow, right?7
u/Beautiful_Stage5720 Jul 04 '26
What the hell?
1
u/gm310509 Jul 05 '26
You might be better off writing a "multiply" function that performs that multiplication in assembly language, then checks the V/OF bit in the status register and flags the overflow if it occurs.
-7
u/amondb Jul 04 '26
Thanks for the guidance. To clarify, I wrote the core C logic and memory boundary checks myself to learn secure coding. I only used AI to help refine the README structure and format the compilation guide efficiently. It's not a low-effort generator project!
0
u/[deleted] Jul 05 '26
[deleted] — view deleted comment