Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Microsoft bans memcpy() (msdn.com)
7 points by ilitirit on May 15, 2009 | hide | past | favorite | 3 comments



There are two problems with this approach.

One, the default implementation of the error handler is a crash at runtime to "detect" the buffer size difference. Or, a custom handler can be used.

Worst case, this handler is turned off, truncation is silent, and overflow occurs the next time the buffer is used. Best case, the handler detects a problem, requiring new code to find minimum buffer size (that should have been there anyway); at which point, it's perfectly safe to use...the standard memcpy()!!!

Two, Microsoft's compiler warning spam recommends replacing standard calls with its own. The warnings often make legitimate uses of memcpy() look wrong in some way.

I sure hope I'm missing something, but this seems like a big waste of time.


So they're replacing

  memcpy(dst, src, len)
with

  memcpy_s(dst, dst_len, src, src_len)
To me, this seems a little desperate. Aren't they just shifting the bugs to a later stage? I guess a spurious read is slightly better than a spurious write, but it all seems incredibly arbitrary.


Yet another case of "I'm Microsoft, and I know better." Lovely.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: