Live data from Hacker News

Android Project Changeset 4f8b683: libc/memset.c

review.source.android.com

91–93 of 93 posts

Re: Android Project Changeset 4f8b683: libc/memset.c

#91

Earlier quoted context omitted.

Practicality. Generally your stdlib is part of your cross compiler install. So now you'd need 2 versions of your stdlib--the small version and the speedy version. So now you aren't using -lc (which is usually built-in to the linker) foro your boot code but you are for your regular firmware. Now your makefile is more complex. And you are running a modified std library so it's a pain to upgrade. Blah blah blah the list…

Compilers have long ago memorized the code for memset (and memcopy and ...) and substitute optimized algorithms. As part of faking their benchmark stats for marketing purposes. So no worries, this code should result in kick-butt optimized assembler. Except for the obvious bug.

Optimized for what? Speed? While I can picture that happening, it has been my experience that this is not the case. The memory squishing optimizations I'm talking about require dumping the assembly output and I've never seen my stupid memcpy() routine suddenly turn into optimized-for-speed code. I'd be pretty upset if that were to happen...

Re: Android Project Changeset 4f8b683: libc/memset.c

#92
post #80

Now this is hacker news. We don't see too many of these types of posts.

No, this is The Daily WTF. "Oh look, someone wrote some really stupid code!" Who cares? How does it enrich us to know that someone mis-implemented memset() in a bootloader that possibly never even calls it, or if it does, probably passes zero as the argument anyway? (Or is dead code because on any arch anyone uses, memset() is implemented in asm.)

It enriched me to learn what memset was. I love hacker news, but I wouldn't mind a few more posts that contain some code.

Re: Android Project Changeset 4f8b683: libc/memset.c

#93

Earlier quoted context omitted.

memset sets a block of memory to a given value. It is often used to initialize an uninitialized block of memory to 0. So often, in fact, that this bug where it always initialized the memory to 0 survived so long.

So often, in fact, that this bug where it always initialized the memory to 0 survived so long. Given that the bug went undetected for so long, I think you could almost reasonably claim that calling memset with a nonzero parameter is a "corner case" ;)

It is a "corner case," or close to it, but that's not why it wasn't caught here. I don't think this code is ever called, as explained above. It's default code in case there isn't a platform specific version, but there pretty much always is a platform specific version.

Link: http://news.ycombinator.com/item?id=1379639

Post reply on HN