Hi.
I'm getting an invalid read of size 8 warning with the code (check.c)
below.Everything seems to be fine, and the warning about reading beyond the
allocated source pointer comes only when I'm copying the source to a particular
index of the destination.
My environment:- MacOSX Darwin 10.8.0 Darwin Kernel Version 10.8.0-
valgrind-3.7.0- gcc version: i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple
Inc. build 5666) (dot 3)
Any clues on why this could happen?
Thanks.- tan
check.c-------------------------------------------------------------------#include
<stdio.h>#include <stdlib.h>#include <pthread.h>#include <assert.h>#include
<time.h>#include <unistd.h>#include <string.h>
#define NUM_E 3
typedef struct mvk_lruc_kv { long l1; long l2; char
c[129];} mvk_lruc_kv_t;
int main(void) { mvk_lruc_kv_t *p1 = malloc(NUM_E *
sizeof(mvk_lruc_kv_t)); mvk_lruc_kv_t *p2 = malloc(30 *
sizeof(mvk_lruc_kv_t));
printf("sizeof(mvk_lruc_kv_t)=%ld, %p, %p, %p, %p\n",
sizeof(mvk_lruc_kv_t), p2, p2+1, p2+2, p1);
memset(p1, 0, sizeof(mvk_lruc_kv_t));
int i = 0; for(i=0; i<(30-NUM_E); i++) {
printf("at index %d\n", i); memcpy(p2+i, p1,
NUM_E*sizeof(mvk_lruc_kv_t)); printf("end at index %d\n", i);
}
return i;}
------------------------------------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users