top | item 26601277

(no title)

david_for_you | 5 years ago

This seems to be missing a return in the NULL check for handle in the match_file function. This leads to fgets being called with a NULL pointer, which I don't know what it does, it may be OK.

I would argue that this is why a "better C" can be useful, it's the kind of error that would be much harder to make in rust.

discuss

order

lew89|5 years ago

There is missing NULL check, but it doesn't crash, because the function would get nonexistent filename only if filesystem driver would do something strange (or file would be deleted just between readdir and fopen). xD I also noticed, that I don't close files and directories. Not a big deal, because fully functional and 100% correct program wasn't the goal here. :)

EDIT: Actually fopen would return NULL when file is not readable. My bad. Anyway, such problems are trivial to debug.

carols10cents|5 years ago

I like that I don't have to spend the time debugging trivial problems like these in Rust though. The compiler catches them for me, and I get more time and brain power to spend debugging nontrivial problems. It adds up.

e12e|5 years ago

> Not a big deal, because fully functional and 100% correct program wasn't the goal here

Wasn't it? It reminds me about the old article by Strostrup on c/c++ for beginners (I seem to link to this quite often, apologies if it gets repetitive):

https://www.drdobbs.com/learning-standard-c-as-a-new-languag...

One point of using c++ over c is that it should be easier to get a program that is in fact correct - regarding things like closing files etc. (that said conciously leaking some recources ("do and die") could be considered idiomatic c i suppose).