Comment

Comment by compi

The first half was a surprisingly ok intro to unicode and utf encodings in C. Super clearly illustrated a handful of pitfalls of trying to roll your own utf8 handling code in C.

But it irks me when rust blogs misrepresent C to show that Rust is better:

    How nice. We even use const in all
    the right places! I think! Except
    maybe argv! Who knows? The compiler
    sure doesn't seem to care much. I
    guess casting non-const to const is
    pretty harmless. Fair enough, GCC,
    fair enough.

    Lucky toupper has no way to return
    an error and just returns 0 for 0,
    right? Or maybe 0 is what it returns
    on error? Who knows! It's a C API!
    Anything is possible.
Both of these have defined answers written into the C standard itself.

Also you can have const memory in C that will crash if you cast it to non-const and write to it. You can call out to the OS to mark a chunk of memory it as read only. The reason it's not as built into C as it is for Rust is that C was in part designed for and currently runs on hardware where there isn't read-only-memory outside of a physical ROM chip.

    So the problem here is that… we
    allocate enough room for “DOG\0”,
    but we end up converting “doggo
    override\0” to uppercase, so we end
    up writing past the area that malloc
    allocated for us.  I believe the
    technical term is a fucky wucky
    buffer overflow.
Something about this sentence screams Rust programmer but I can't put my finger on why.
parent compi 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton