C considered dangerous
C considered dangerous
Posted Sep 5, 2018 9:08 UTC (Wed) by johill (subscriber, #25196)In reply to: C considered dangerous by anton
Parent article: C considered dangerous
memcpy_s(buf,sizeof(buf),src,len);
in this case, I guess.
Posted Sep 5, 2018 9:23 UTC (Wed)
by anton (subscriber, #25547)
[Link]
Posted Sep 5, 2018 10:12 UTC (Wed)
by excors (subscriber, #95769)
[Link]
Posted Sep 5, 2018 10:21 UTC (Wed)
by pizza (subscriber, #46)
[Link]
(Personally, most uses of 'memcpy' in my code involve assembling chunks of data into a buffer. Nearly all of the memcpy()s' destinations are at nonzero offsets of the original buffer, so memcpy_s() really doesn't do me any good...)
Yes, that's even better. I was actually thinking about the maintenance programmer changing the len parameter of memcpy (to, say, len+a-b), and forgetting to change the assertion; there are often stale comments, so I would not be surprised about stale assertions (unless the tests cause them to trigger).
C considered dangerous
C considered dangerous
C considered dangerous
