da_cow (she/her)@feddit.org to Programmer Humor@programming.dev · 3 days agoI got to avoid memory management for quite some timefeddit.orgimagemessage-square65linkfedilinkarrow-up1332arrow-down112file-text
arrow-up1320arrow-down1imageI got to avoid memory management for quite some timefeddit.orgda_cow (she/her)@feddit.org to Programmer Humor@programming.dev · 3 days agomessage-square65linkfedilinkfile-text
Finally I have a valid reason to learn about memory management. It was also hella weird when encountering it.
minus-squareLedgeDrop@lemmy.ziplinkfedilinkarrow-up17·3 days agoWithout getting too critical of your code (congrats BTW), never use strcpy instead use strlcpy. strcpy will happily allow you to create buffer overflows (a common challenge with C) which will cause your application to crash. You’ll find more details here. Good luck!
minus-squareda_cow (she/her)@feddit.orgOPlinkfedilinkarrow-up9·3 days agoThanks, I did not knew this. I always appreciate constructive criticism. I am quite new to C so theres a shit ton of stuff I have never done or dont even know about.
minus-squareozymandias117@lemmy.worldlinkfedilinkEnglisharrow-up6·3 days agoAnd understand when you can use them… I’ve seen too much code following this advice blindly that just does something like strncpy(dst, src, strlen(src))
Without getting too critical of your code (congrats BTW), never use
strcpy
instead usestrlcpy
.strcpy
will happily allow you to create buffer overflows (a common challenge with C) which will cause your application to crash.You’ll find more details here.
Good luck!
Thanks, I did not knew this. I always appreciate constructive criticism. I am quite new to C so theres a shit ton of stuff I have never done or dont even know about.
And understand when you can use them…
I’ve seen too much code following this advice blindly that just does something like
strncpy(dst, src, strlen(src))