Hacker News new | past | comments | ask | show | jobs | submit login

Agree about strdup(), but as the author says, it's a performance issue, not a correctness one.

As for static strings... I think it'd be pretty hard to convince people that

    strcpy(err->message, "out of memory");
is somehow much worse than

    static const char oom[] = "out of memory";
    static_assert(sizeof(err->message) >= sizeof(oom));
    memcpy(err->message, oom, sizeof(oom));
especially if "err->message" is very long.

(That said, I personally prefer to use asprintf/snprintf even for static strings, for consistency's sake)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: