可能由_wordcopy_fwd_dest_aligned 引起的一处内存出错

来源:互联网 发布:广东windows 98 编辑:程序博客网 时间:2024/05/31 13:14
 ==28356== Thread 9:1481 ==28356== Invalid read of size 81482 ==28356==    at 0x3328A7BA95: _wordcopy_fwd_dest_aligned (in /lib64/libc-2.5.so)1483 ==28356==    by 0x3328A7B0FF: bcopy (in /lib64/libc-2.5.so)1484 ==28356==    by 0x5E3C45: unsigned int CSocket::packetPackZip<ByteBuffer<unsigned char [65560]> >(void const*, unsigned int, ByteBuffer<unsigned char [65560]>&, bool) 

        这是通过memcheck检查到的一个内存读错误,

        发现可能是因为 _wordcopy_fwd_dest_aligned 偏移对齐的操作引起的

http://www.oschina.net/code/explore/glibc-2.9/sysdeps/powerpc/powerpc32/power4/wordcopy.c

/** _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to
064   block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
065   DSTP should be aligned for memory operations on `op_t's, but SRCP must
066   *not* be aligned.  */
067 
068void
069_wordcopy_fwd_dest_aligned (dstp, srcp, len)
070     long int dstp;
071     long int srcp;
072     size_t len;
073{
074  op_t a0, a1, a2;
075  int sh_1, sh_2;
076 
077  /** Calculate how to shift a word read at the memory operation
078     aligned srcp to make it aligned for copy.  */
079 
080  sh_1 = 8 * (srcp % OPSIZ);
081  sh_2 = 8 * OPSIZ - sh_1;
082 
083  /** Make SRCP aligned by rounding it down to the beginning of the `op_t'
084     it points in the middle of.  */
085  srcp &= -OPSIZ;
086  a0 = ((op_t *) srcp)[0];
087 
088  if (len & 1)
089  {
090    a1 = ((op_t *) srcp)[1];
091    ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
092     
093    if (len == 1)
094      return;
095     
096    a0 = a1;
097    srcp += OPSIZ;
098    dstp += OPSIZ;
099    len -= 1;
100  }
101 
102  do
103    {
104      a1 = ((op_t *) srcp)[1];
105      a2 = ((op_t *) srcp)[2];
106      ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
107      ((op_t *) dstp)[1] = MERGE (a1, sh_1, a2, sh_2);
108      a0 = a2;
109 
110      srcp += 2 * OPSIZ;
111      dstp += 2 * OPSIZ;
112      len -= 2;
113    }
114  while (len != 0);
115}
              暂时没有想到很好的解决方案,先用memmove 代替 bcopy

原创粉丝点击