• uis@lemm.ee
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    4 months ago

    If n is smaller than the string length (as in: distance to first null byte) then you’re bound to have garbage in your return destination

    Wha? N is just maximum length of string to copy. Data after dst+n is unchanged.

    In retrospect null-terminated strings were a mistake, but so were many other things, at some point you just have to accept that there’s hysterical raisins everywhere.

    All hail length-prefixed strings!

      • uis@lemm.ee
        link
        fedilink
        arrow-up
        1
        ·
        4 months ago

        Let us not talk about situations where CHAR_BIT != 8 that’s not POSIX anyway.

        Yeah, let’s not talk about 20-bit one’s complement ints.