r/C_Programming • u/lehmagavan • Sep 05 '26
Data container - old newbish project revised
Some time ago I posted here my C implementation of a dynamic data container (vector like object):
https://github.com/andrzejs-gh/CONTLIB
I revised it, if anyone's interested take a look. Any feedback and tips very much welcome.
0
Upvotes
âĸ
u/github-guard Sep 05 '26
đ GitHub Guard: Trust Report
â ī¸ This project scored 2/6 â below this subreddit's threshold of 3.
Audit Breakdown:
4
u/skeeto Sep 05 '26
I'm a fan of type-paramaterized macros like
cont_NEW. I don't see that often. Programs are cleaner with those than hazardous operations involving thesizeofoperator. I like thatcontobjects are not allocated by the library, and returned by copy from the "ctor." Good job on your integer overflow checks. You say your project is "newbish" but even pros miss these all the time.I don't like that it doesn't support zero-capacity containers, and that requesting one produces and invalid container. Zero-capacity things are useful, and can be created without allocating (i.e. without error handling).
I also don't like that API misuse is treated as an error instead of a hard assert/abort. This hides defects and leads to more fragile software, especially at a time when automated testing is growing ever more important. Failure to allocate is an error, but using an invalid
contis a defect and should abort because the program got into an invalid state. Along these lines, using in invalidcontwithcont_growor anything that calls it likecont_pushcauses and infinite loop.This program demonstrates two different bugs:
Then:
First, there's an integer overflow causing the library to report it successfully allocated an impossible amount of memory, when it actually did nothing. After that
cont_mkroomoverflows the buffer whencount == capacity. So just a couple missing checks.1
u/AutoModerator Sep 05 '26
Hi /u/lehmagavan,
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.