coding in C until I commit an atrocity

preview_player
Показать описание
In this video I try my very best to complete my C programming homework without committing several catastrophes, however this C code may be haunted.

0:00 - God tier coding
0:45 - Haunted code
Рекомендации по теме
Комментарии
Автор

lmao. I always forget to make the string length + 1 to account for the NUL byte

breadcodes
Автор

That would’ve taken me a solid 5 hours. Super god tier coding

TheControlMastr
Автор

Man I am disappointed in myself for not figuring it out after coding in C so much, I peeked at the comments and immediately slapped myself in the face over how obvious it was

spoobspoob
Автор

For those who didn’t find the issue:
strlen gets the length of the string so the strcopy only copied the string but not the null terminator. That isn’t that bad until you realize that he is using a strcompare which requires the null terminator.

spookycode
Автор

VLA is a code smell. Use a large enough buffet or malloc. While at it, don't forget the null terminator.

abiiranathan
Автор

You already commited an atrocity with those bracket placements

heart_locket
Автор

Are you using a c99 variable length array for the string? Instead of using malloc?

petrlaskevic
Автор

I would say use strcpy but that is iffy security wise (what are you even using C for security anyways?) so instead memcpy with len + 1 to include NULL at the end will fix it. Easy mistake.

yonderalt
Автор

I made this mistake with arrays in Javascript (Yes beat me up for using Javascript) wondering why there was 1 entry missing.
So now I always do a +1 :)

randomdamian
Автор

Does this code have a chance to work, if 0 happens to be in memory after allocated password buffer?

АлексейСтах-зн
Автор

What's actually wrong with the code? Like what is causing that bug?

Jerios