Live data from Hacker News

Android Project Changeset 4f8b683: libc/memset.c

review.source.android.com

1–10 of 93 posts

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

#3
post #2

Can someone who lives in the world of C fill in the blanks? If this was a major typo, I have done things along those lines.

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.

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

#4
post #2

Can someone who lives in the world of C fill in the blanks? If this was a major typo, I have done things along those lines.

The function was always setting the memory to 0 instead of what was passed in. I think most uses of memset are to initialize memory to 0, but any other use would have had unexpected results.

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

#5
post #2

Can someone who lives in the world of C fill in the blanks? If this was a major typo, I have done things along those lines.

memset's job is to fill a block of memory with a given byte. The most common fill byte is 0, to initialize or otherwise clear a buffer. It looks like it is so common, in fact, that a programmer accidentally made Android's memset _always_ fill with 0, no matter what byte was passed in, and presumably no one noticed for a while. (I can't figure out when this patch was introduced.)

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

#6
post #2

Can someone who lives in the world of C fill in the blanks? If this was a major typo, I have done things along those lines.

Memset (according to the c++ reference) is supposed to: "Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char)."

So, give it a pointer to some memory, give it a value and the number of bytes you want to set and it'll go wild. In this case, memset was just blindly dropping in zeroes into the memory block

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

#7
post #5
post #2

Can someone who lives in the world of C fill in the blanks? If this was a major typo, I have done things along those lines.

memset's job is to fill a block of memory with a given byte. The most common fill byte is 0, to initialize or otherwise clear a buffer. It looks like it is so common, in fact, that a programmer accidentally made Android's memset _always_ fill with 0, no matter what byte was passed in, and presumably no one noticed for a while. (I can't figure out when this patch was introduced.)

The "Up to change" link takes you to the summary. May 13, 2010

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

#8
post #2

Can someone who lives in the world of C fill in the blanks? If this was a major typo, I have done things along those lines.

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.

Wish there was a cross-link to a bug tracking system where this was initially reported.

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

#9
The thing that shocks me about this bug is that it should have been caught when the compiler issued a warning about an unused function parameter. Either the warning was not enabled, or the programmer just ignored it; either of those options indicates a pretty severe lack of professionalism.

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

#10
post #8

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.

Wish there was a cross-link to a bug tracking system where this was initially reported.

You can just search for the change ID:

https://review.source.android.com/#change,14699

Post reply on HN