3 ms·
I've never been a fan of: while (s++ = t++); I think it pretty just make the code harder to read. (Ok, maybe on some compilers it can be faster). I mean, everyt
by d0m 17y ago
I've never been a fan of: while (s++ = t++); I think it pretty just make the code harder to read. (Ok, maybe on some compilers it can be faster). I mean, everytime I see a line like that, I always assume there's a nasty bug hidden in it and I spend lots of time looking at it to be 100% sure there isn't.
- InclinedPlane 17y agoThere is a nasty bug in it, a buffer overrun bug. If, for any reason, t is not properly null terminated, then you'll have a problem. If, for any reason, s is not at least as large of a buffer as t, then you'll have a problem. How bad of a problem? Well, quite potentially the worst kind: a serious buffer overflow problem that could result in a remote execution vulnerability. This is just the sort of thing that gets patched every Tuesday as engineers come to the "oh shit!" realization that yet another bit of crusty code using some ancient "clever" (actually lazy) idiom has been sitting around just waiting for some ne'er do well to take advantage of it and create yet another 400,000 system botnet. It's good to have a solid knowledge of C programming fundamentals, but actually writing good, safe C code is non-trivial. Moreover, the mentality that one can just slap together some "efficient" C code and ship it out the door has resulted in more heartache and more sysiphean turd polishing than almost any other single software engineering mistake.
- SamReidHughes 17y agoThat's not a bug, that's strcpy. You are being hysterical.