Date: Wed, 24 Feb 2010 16:44:35 +0300 From: Andrey Zonov <andrey.zonov@gmail.com> To: freebsd-hackers@freebsd.org Subject: 2 bytes allocated problems Message-ID: <983a1cf21002240544s59006035ifbf0ef7eb045e44f@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hi,
When I try allocated pointer to a pointer, and in it some pointers
(important: size is 2 bytes), the pointers lose their boundaries.
Why it can happen?
Test program in attach.
PS in freebsd < 7, it's ok, in Linux too.
--
Andrey Zonov
[-- Attachment #2 --]
/*
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define S1 "ab"
#define S2 "cd"
static void *Malloc(size_t size);
int
main(void)
{
char **pp;
pp = (char **) Malloc(2 * sizeof(char *));
pp[0] = (char *) malloc(2);
memcpy(pp[0], S1, 2);
pp[1] = (char *) malloc(2);
memcpy(pp[1], S2, 2);
printf("%s\n", *pp);
printf("%s\n", pp[0]);
printf("%s\n", pp[1]);
exit(0);
}
static void *
Malloc(size_t size)
{
void *p;
p = malloc(size);
if (p == NULL)
err(1, "malloc()");
return(p);
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?983a1cf21002240544s59006035ifbf0ef7eb045e44f>
