From owner-freebsd-current@FreeBSD.ORG Wed Jan 28 12:10:08 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D321D1065D0F for ; Wed, 28 Jan 2009 12:10:08 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.freebsd.org (Postfix) with SMTP id 126438FC24 for ; Wed, 28 Jan 2009 12:10:07 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: (qmail invoked by alias); 28 Jan 2009 12:10:06 -0000 Received: from p54A3E68D.dip.t-dialin.net (EHLO tron.homeunix.org) [84.163.230.141] by mail.gmx.net (mp008) with SMTP; 28 Jan 2009 13:10:06 +0100 X-Authenticated: #1673122 X-Provags-ID: V01U2FsdGVkX1+Jm34bFUyJg+6MtG9BlZd8RdqdeoN2OvAWM1/Sn5 tEW0V0jRpXPvYX Message-ID: <49804B1E.7080603@gmx.de> Date: Wed, 28 Jan 2009 13:10:06 +0100 From: Christoph Mallon User-Agent: Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: Channa References: <515c64960901280339m17fa9309v2e1bc3f55454ab@mail.gmail.com> <49804597.6040303@gmx.de> <515c64960901280401w1e1d08bfx29adc124bc749c4a@mail.gmail.com> In-Reply-To: <515c64960901280401w1e1d08bfx29adc124bc749c4a@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-FuHaFi: 0.6 Cc: freebsd-current@freebsd.org Subject: Re: Jemalloc SEGV for 1MB chunk X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jan 2009 12:10:21 -0000 Channa schrieb: > Hi, > Thanks for your reply. > You mean to say i should modify the test as below: > > #include > #include > #include > > > int main() > { > int i; > char *buf; > size_t size = 1048576 ; > > buf = malloc(size); > for (i = 0; i <= 1048575; i++) > buf[i] = 'a'; > buf[size]='\0'; > printf("The length of buff is : %d\n",strlen(buf)); > free(buf); > return 0; > } > > I NULL terminated the string > buf[size] = '\0' <== The last character is NULL > > But still i get a SEGV at strlen. > > Could you please tell me if my changes above are correct? You write the '\0' one element past the end of the buffer. The buffer has 1.048.576 elements, the indices go from 0 to 1.048.575. This is *the* typical off-by-one error. It most probably does not segfault at the strlen(), but when writing the '\0'.