Snowel Xue wrote:
>
> Let's run once as one example, b[] is "3c 08 00 01 ....." ,step=4,
> bidx=0, bc=0x1000
> if run this code
> for (j = step; j > 0 && bc > 0; j--)
> {
> if (urj_big_endian)
> {
> data |= b[bidx++];
> data <<= 8;
> }
> then there are 4 loops
> 1st: data |= b[bidx++]; data = 0x3c
> data <<= 8; data = 0x3c00
> 2nd: data |= b[bidx++]; data = 0x3c08
> data <<= 8; data = 0x3c0800
> 3rd: data |= b[bidx++]; data = 0x3c0800
> data <<= 8; data = 0x3c080000
> 4th: data |= b[bidx++]; data = 0x3c080001
> data <<= 8; data = 0x08000100
> then at the end, get 0x08000100, so we lost the first byte 0x3c
>
> anything wrong ?
OK, I see now, you are right. I will apply the patch.
Rutger
> ----- 原文 -----
>
> 发件人: Rutger Hofman
> 主 题: Re: [UrJTAG-dev] Is there a bug in writemem.c for big endian ?
> 时 间: 2009年11月16日 18时33分51秒
> 抄 送: [email protected],
>
> Snowel Xue wrote:
> > Hi
> > I found there is one bug here:
> > orignal code:
> > /* Write a word at a time */
> > data = 0;
> for (j = step; j > 0 && bc > 0; j--)
> > {
> > if (urj_big_endian)
> > {
> > data |= b[bidx++];
> > data <<= 8;
> > }
> > else
> > data |= (b[bidx++] << ((step - j) * 8));
> > bc--;
> > }
> > it should move "data <<= 8;" before "data |= b[bidx++];", or else, it
> cause one byte overflow.
> > the correct code should be:
> >
> > /* Write a word at a time */
> > data = 0;
> > for (j = step; j > 0 && bc > 0; j--)
> > {
> > if (urj_big_endian)
> > {
> > data <<= 8;
> > data |= b[bidx++];
> > }
> > else
> > data |= (b[bidx++] << ((step - j) * 8));
> > bc--;
> > }
>
> Hmmm. I don't see the bug. After the loop, variable data points past the
> array, but that is no problem because it is not accessed. In your fix,
> the first byte of data is not written.
>
> Rutger
> Best Regards
>
> ------------------------------------------------------------------------
>
> 你今天猎婚了吗?马上投猎婚简历
> <http://sohu.ad-plus.cn/event.ng/Type=click&FlightID=200911&TargetID=sohu&Values=9b0b465f,3c44ec21,858b49d3,4023999f&AdID=10093>
>
>
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> UrJTAG-development mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/urjtag-development
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development