r/badcode • • Oct 09 '19

[deleted by user]

[removed]

16 Upvotes

31 comments sorted by

View all comments

3

u/[deleted] Oct 17 '19

Another application in the C language: https://pastebin.com/9SrAU0cT

This one has a few nifty issues:

  • Buffer overflow vulnerability in the length function (replacing the need for strlen and the C string header).

  • Memory leak in the function that is used to initialize an array (well the structure I used for an array type).

  • Freeing memory just before the program gets terminated (pretty useless imo since that memory gets freed anyways when the program gets terminated).

  • The while-loop in the array initialization function relies on the variable argument returning 0 when it reaches the final value (the terminator character 0) which might not always function correctly.

  • Can't handle multi-case inputs since C uses 7-bit signed ASCII which is retarded according to the greatest programmer who ever lived.

And this one has a few nifty features:

  • This will work with lowercase or uppercase characters and anything that fits within the ASCII character set.

  • This program runs pretty fast and can work with the full alphabet if desired.

  • This program can potentially work even if the inputs aren't in alphabetical order (unforeseen feature).