da_cow (she/her)@feddit.org to Programmer Humor@programming.dev · 1か月前I got to avoid memory management for quite some timefeddit.orgimagemessage-square62linkfedilinkarrow-up1346arrow-down113file-text
arrow-up1333arrow-down1imageI got to avoid memory management for quite some timefeddit.orgda_cow (she/her)@feddit.org to Programmer Humor@programming.dev · 1か月前message-square62linkfedilinkfile-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·1か月前Without 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-up10·1か月前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.
minus-squareozymandias117@lemmy.worldlinkfedilinkEnglisharrow-up6·1か月前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))
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))