ss7m / paleofetch

neofetch, but written in C
MIT License
167 stars 50 forks source link

Handle cache misses gracefully #37

Closed allisio closed 4 years ago

allisio commented 4 years ago

If the user changes their config to cache a new value, recompiles, and then runs paleofetch without --recache, we segfault when we go looking for the new key in the now-stale cache.

This patch fixes that by checking whether strstr() found something and bails if it didn't, guiding the user in the direction of the fix.

Because this seemed like a good use case for a formatted exit message, halt_and_catch_fire() was refactored to behave like fprintf(stderr, ...).

Token-pasting __VA_ARGS__ is a widely adopted extension (at least, GCC and Clang have supported it for ages) that I made use of so that I didn't have to touch any other calls to halt_and_catch_fire(). Without the ##, they'd leave a trailing comma in the expansion and result in invalid syntax.

ss7m commented 4 years ago

When you have a macro which expands into a statement, isn't it best practice to wrap it in

do {
    /* Statement here */
} while (0)