On Saturday 14 November 2009, Zach Welch wrote: > On Sat, 2009-11-14 at 12:56 -0700, David Brownell wrote: > > On Saturday 14 November 2009, Zachary T Welch wrote: > > > - for (unsigned i = 0, num_bytes = CEIL(size, 8); i < num_bytes; > > > i++) > > > - to[i] = from[i]; > > > + // copy entire buffer > > > + memcpy(_to, from, CEIL(size, 8)); > > > > Comment is wrong: copies all but trailing partial byte. > > CEIL is a strange name for converting a bit count to byte count.
It's a rounding thing; "8" is what makes it perform such a conversion. I'd be happier if it were called DIV_ROUND_UP() like a certain OS kernel I could mention ... not as cryptic. (Likewise, there's a DIM which is used for ARRAY_SIZE. And lots of re-inventions of that, since DIM is a really un-obvious name for "what size is this array".) > From > src/helper/binarybuffer.h: > > #define CEIL(m, n) (((m) + (n) - 1) / (n)) > > Or is my brain not interpreting that code correctly? Or maybe I was. Given that it copies everything, why is there code *after* the copy mangling the last byte? Wouldn't that only be correct when the code copied all but the trailing partial byte? Looks to me like this code has always been trashing that last byte. So "size/8" would be correct ... not rounding up, just copy the whole bytes, then masking in the trailing bits. - Dave _______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development