dirtbags / fluffy

Tools for Network Archaeology (internet protocol analysis)
Other
27 stars 9 forks source link

End on feof() and not EOF #3

Closed SamAxe closed 3 years ago

SamAxe commented 3 years ago

No idea if this behavior is intended or just a hassle.

SamAxe commented 3 years ago

For puzzle 25000

cat puzzle.pcap|./pcat | awk '(NR > 3) { print $6; }' | grep -v "^0000000000$" | while read line; do echo $line | ./unhex ; done

pi-rho commented 3 years ago

feof vs EOF I don't think it matters. getchar explicitly returns EOF on EOF.

On one hand, testing for EOF or running feof() right after getchar is best practice, and you advance the counter before the switch. On the other hand, within this scope, you only use count var on one of the switch cases; the return exits the scope.

@SamAxe's example doesn't blow up for me.

pi-rho commented 3 years ago

Another point, testing an integer equality against a macro is cheaper than executing a function call.

SamAxe commented 3 years ago

Probably something weird in my environment or shell. I'd just close the PR at this point.

agausmann commented 3 years ago

feof and an EOF return value aren't equivalent. EOF can also be returned if there is an error that can be checked with ferror.

nealey commented 3 years ago

Right, so anything removing the EOF check ought to also check ferror so we don't start trying to process garbage data...