From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/266 Path: news.gmane.org!not-for-mail From: JIghtuse Newsgroups: gmane.linux.lib.musl.general Subject: malloc testing (was: Simple testing task - string functions) Date: Sun, 10 Apr 2011 22:59:08 +0700 Message-ID: <4DA1D3CC.1090008@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; X-Trace: dough.gmane.org 1312595694 11348 80.91.229.12 (6 Aug 2011 01:54:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2011 01:54:54 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: envelope-from@hidden Sun Apr 10 19:59:34 2011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; DomainKey-Signature: a=rsa-sha1; c=nofws; User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20110307 Icedove/3.0.11 Xref: news.gmane.org gmane.linux.lib.musl.general:266 Archived-At: This is a multi-part message in MIME format. --------------000302000502000803090808 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit -------- Original Message -------- Subject: Re: [musl] Simple testing task - string functions Date: Sun, 10 Apr 2011 22:25:59 +0700 From: JIghtuse To: musl@lists.openwall.com I have some questions about my task. I've written a program to test malloc() function of musl. But.. 1. Can I use standart rand() and srand() functions to generate random size of allocated memory chunks, or I must to write another one random number generator? 2. Write a program which loops many times allocating and freeing memory So, when my program must to free memory? If it freeing just after its allocating, it always gets one chunk of memory. And how to define maximum size of memory chunk? I define it as MAX_SIZE / 1000, where MAX_SIZE is a maximum total allocated amount (about 8 * 10^8). Is it correctly? 3. I decided to generate a fragmentation diagram as a .dat file for plotting by gnuplot. Are you satisfied with it, or maybe write it as a simple text file with pseudo-graphic diagram? Thanks. I await your reply. UPD. I'm sorry for mixed tho threads, its really bad. -- Sincerely yours, JIghtuse. --------------000302000502000803090808 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit

-------- Original Message --------
Subject: Re: [musl] Simple testing task - string functions
Date: Sun, 10 Apr 2011 22:25:59 +0700
From: JIghtuse <jightuse@gmail.com>
To: musl@lists.openwall.com


I have some questions about my task. I've written a program to test 
malloc() function of musl. But..
1. Can I use standart rand() and srand() functions to generate random 
size of allocated memory chunks, or I must to write another one random 
number generator?
2.

Write a program which loops many times allocating and freeing memory

So, when my program must to free memory? If it freeing just after its 
allocating, it always gets one chunk of memory. And how to define 
maximum size of memory chunk? I define it as MAX_SIZE / 1000, where 
MAX_SIZE is a maximum total allocated amount (about 8 * 10^8). Is it 
correctly?
3. I decided to generate a fragmentation diagram as a .dat file for 
plotting by gnuplot. Are you satisfied with it, or maybe write it as a 
simple text file with pseudo-graphic diagram?
Thanks. I await your reply.


UPD. I'm sorry for mixed tho threads, its really bad.
-- 
Sincerely yours, JIghtuse.

--------------000302000502000803090808-- From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/294 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: malloc testing (was: Simple testing task - string Date: Wed, 20 Apr 2011 00:34:09 -0400 Message-ID: <20110420043409.GK277@brightrain.aerifal.cx> References: <4DA1D3CC.1090008@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1312595709 11486 80.91.229.12 (6 Aug 2011 01:55:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2011 01:55:09 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: envelope-from@hidden Wed Apr 20 08:39:27 2011 Content-Disposition: inline In-Reply-To: <4DA1D3CC.1090008@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:294 Archived-At: On Sun, Apr 10, 2011 at 10:59:08PM +0700, JIghtuse wrote: > I have some questions about my task. I've written a program to test > malloc() function of musl. But.. Any updates? Are you still interested in working on this? Rich From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/296 Path: news.gmane.org!not-for-mail From: JIghtuse Newsgroups: gmane.linux.lib.musl.general Subject: Re: malloc testing Date: Thu, 21 Apr 2011 09:11:37 +0700 Message-ID: <4DAF9259.10300@gmail.com> References: <4DA1D3CC.1090008@gmail.com> <20110420043409.GK277@brightrain.aerifal.cx> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1312595710 11492 80.91.229.12 (6 Aug 2011 01:55:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2011 01:55:10 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: envelope-from@hidden Thu Apr 21 06:12:05 2011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; DomainKey-Signature: a=rsa-sha1; c=nofws; User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20110307 Icedove/3.0.11 In-Reply-To: <20110420043409.GK277@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:296 Archived-At: On 20.04.2011 11:34, Rich Felker wrote: > On Sun, Apr 10, 2011 at 10:59:08PM +0700, JIghtuse wrote: > >> I have some questions about my task. I've written a program to test >> malloc() function of musl. But.. >> > Any updates? Are you still interested in working on this? > > Ricih > Yes, I interested in. Just some studying. Can you give some algorithms? I not found its on the Net. How chunks should be flipped? -- Sincerely yours, JIghtuse. From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/297 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: malloc testing Date: Thu, 21 Apr 2011 02:00:57 -0400 Message-ID: <20110421060057.GR277@brightrain.aerifal.cx> References: <4DA1D3CC.1090008@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1312595710 11494 80.91.229.12 (6 Aug 2011 01:55:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2011 01:55:10 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: envelope-from@hidden Thu Apr 21 10:06:25 2011 Content-Disposition: inline In-Reply-To: <4DAF9259.10300@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:297 Archived-At: On Thu, Apr 21, 2011 at 09:11:37AM +0700, JIghtuse wrote: > On 20.04.2011 11:34, Rich Felker wrote: > >On Sun, Apr 10, 2011 at 10:59:08PM +0700, JIghtuse wrote: > >>I have some questions about my task. I've written a program to test > >>malloc() function of musl. But.. > >Any updates? Are you still interested in working on this? > > > >Ricih > Yes, I interested in. Just some studying. > Can you give some algorithms? I not found its on the Net. How chunks > should be flipped? Try something like: 1. Allocate blocks in random sizes until the total size exceeds the configured limit M. For each block allocated, keep track of its address and size. 2. Sort the allocated block records by size (with the qsort function). 3. Free all but the first 25% in the sorted list (i.e. all but the smallest ones). Leave the ones you don't free in your list. Repeat this procedure a few times, and the last time through, don't free anything. Now sort the records by address instead of by size, and check that they don't overlap. For large allocations (>100k) I would bias the random numbers to be just below a multiple of 4096. Something like: if (size > 100000) size |= 0xff0; This puts them in the "red zone" where bugs could (and in the past did) lead to under-allocation. Rich From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/305 Path: news.gmane.org!not-for-mail From: JIghtuse Newsgroups: gmane.linux.lib.musl.general Subject: malloc testing Date: Wed, 27 Apr 2011 10:24:15 +0700 Message-ID: <4DB78C5F.8030803@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1312595714 11519 80.91.229.12 (6 Aug 2011 01:55:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2011 01:55:14 +0000 (UTC) To: "Musl!" Original-X-From: envelope-from@hidden Wed Apr 27 03:24:43 2011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; DomainKey-Signature: a=rsa-sha1; c=nofws; User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20110307 Icedove/3.0.11 Xref: news.gmane.org gmane.linux.lib.musl.general:305 Archived-At: So, I am still working on testing malloc() of musl. My coding breaks by some increase of studing in university, but I have to say I want to participate. Is it real to join Summer of Security? After finished musl tests I want to try blists development also. -- Sincerely yours, JIghtuse. From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/309 Path: news.gmane.org!not-for-mail From: Solar Designer Newsgroups: gmane.linux.lib.musl.general Subject: Re: malloc testing Date: Fri, 29 Apr 2011 09:42:35 +0400 Message-ID: <20110429054235.GB27053@openwall.com> References: <4DB78C5F.8030803@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1312595717 11533 80.91.229.12 (6 Aug 2011 01:55:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2011 01:55:17 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: envelope-from@hidden Fri Apr 29 05:43:25 2011 Content-Disposition: inline In-Reply-To: <4DB78C5F.8030803@gmail.com> User-Agent: Mutt/1.4.2.3i Xref: news.gmane.org gmane.linux.lib.musl.general:309 Archived-At: JIghtuse - On Wed, Apr 27, 2011 at 10:24:15AM +0700, JIghtuse wrote: > So, I am still working on testing malloc() of musl. My coding breaks by > some increase of studing in university, but I have to say I want to > participate. Is it real to join Summer of Security? Sure. Thanks for the status update. > After finished musl tests Luka is the primary person to work on these, but you're welcome to stay involved as well - e.g., you may help test Luka's tests against more libc's, report problems in here (both those of the tests and of the libc's), and improve the tests. > I want to try blists development also. Sounds good. This is off-topic for the musl list, though, so please e-mail me off-list for it when you're ready. Thanks, Alexander P.S. Somehow you started a new thread instead of posting to the existing thread with the same Subject. You should have used "reply" on a message in the proper thread. From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/28 Path: news.gmane.org!not-for-mail From: JIghtuse Newsgroups: gmane.linux.lib.musl.general Subject: Re: malloc testing Date: Sun, 5 Jun 2011 01:03:18 +0700 Message-ID: References: <4DB78C5F.8030803@gmail.com> <20110429054235.GB27053@openwall.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=90e6ba53a940665edc04a4e6af1d X-Trace: dough.gmane.org 1307210627 5575 80.91.229.12 (4 Jun 2011 18:03:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 4 Jun 2011 18:03:47 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-111-gllmg-musl=m.gmane.org@lists.openwall.com Sat Jun 04 20:03:43 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1QSvCI-0002Im-LB for gllmg-musl@lo.gmane.org; Sat, 04 Jun 2011 20:03:42 +0200 Original-Received: (qmail 9384 invoked by uid 550); 4 Jun 2011 18:03:41 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9376 invoked from network); 4 Jun 2011 18:03:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=a7af4SkctohpW6bZmzlwjPDeNPVeMQmgfZIYBSpRlA0=; b=MGQvQtfcOwEiokWjhFcvkHjTZIah/V78/OwU01Ho5xe/IskTiFw5u4T848txfdKNO+ Ho+3WG31vw4i7fEnhEjNcSiINWcquiBZ1to7ZEHY0Ei67zM9MQmNXvFk+Htb4z/PO2w0 Lmqz+Ic1Ayf1qecLWWc7NNslTkrvSCdjOQbTM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=fo1iiEmllx2RfQPot10BFw5UAaf0aldh1uH73QttOxwZnphfatLpKu6oDDiLSS3G+H GaiDoAXJ5YLNUi1FGHm+t5IRo+ySQWEKs4fBaZ5WVmhnB8/+YBzuGn1NdzY7Rb2Yuc7c B389/f1sFkgJfEdH0lWZTLLEFDO0YwQuZmUZI= In-Reply-To: <20110429054235.GB27053@openwall.com> Xref: news.gmane.org gmane.linux.lib.musl.general:28 Archived-At: --90e6ba53a940665edc04a4e6af1d Content-Type: text/plain; charset=ISO-8859-1 On Fri, Apr 29, 2011 at 12:42 PM, Solar Designer wrote: > JIghtuse - > > On Wed, Apr 27, 2011 at 10:24:15AM +0700, JIghtuse wrote: > > So, I am still working on testing malloc() of musl. My coding breaks by > > some increase of studing in university, but I have to say I want to > > participate. Is it real to join Summer of Security? > > Sure. Thanks for the status update. > > > After finished musl tests > > Luka is the primary person to work on these, but you're welcome to stay > involved as well - e.g., you may help test Luka's tests against more > libc's, report problems in here (both those of the tests and of the > libc's), and improve the tests. > > > I want to try blists development also. > > Sounds good. This is off-topic for the musl list, though, so please > e-mail me off-list for it when you're ready. > > Thanks, > > Alexander > > P.S. Somehow you started a new thread instead of posting to the existing > thread with the same Subject. You should have used "reply" on a message > in the proper thread. > So, my program creates array of structures of memory blocks and works with it. Source code: #include #include #include #include #define M 100000000 #define REPEATS 10 struct block { unsigned int* ptr; unsigned int size; } blocks[M / 100]; int by_size(const void *, const void *); int by_address(const void *, const void *); int main(int argc, char *argv[]) { unsigned int i = 0, j, counter; unsigned int seed; unsigned int amount = 0; unsigned int size; if (argc > 1) { seed = atoi(argv[1]); } else { printf("Type seed: "); scanf("%u", &seed); } bzero(blocks, sizeof(blocks[0]) * (M / 100)); for (counter = 0; counter < REPEATS; counter++) { while (amount < M) { size = rand() % (M / 100); if (size > 100000) { size |= 0xff0; } blocks[i].size = size; blocks[i].ptr = malloc(sizeof(int) * size); if (blocks[i].ptr == NULL) { printf("\nmalloc() error!\n"); exit(EXIT_FAILURE); } amount += blocks[i].size; i++; } if (counter != REPEATS - 1) { qsort(blocks, i, sizeof(struct block), by_size); for (j = i / 4; j < i; j++) { amount -= blocks[j].size; free(blocks[j].ptr); } bzero((void *)(blocks + i / 4), sizeof(blocks[0]) * ((i / 4) * 3 + 3)); i /= 4; } else { qsort(blocks, i, sizeof(struct block), by_address); } } printf("%5s %12s %8s\n", "No.", "Address", "Size"); for (j = 0; j < i - 1; j++) { printf("%5u %12u %8u\n", j, (unsigned int)blocks[j].ptr, blocks[j].size); if (blocks[j].ptr + blocks[j].size >= blocks[j + 1].ptr) { printf("\nOverlaped!\n"); exit(EXIT_SUCCESS); } } printf("%5u %12u %8u\n", j, (unsigned int)blocks[j].ptr, blocks[j].size); exit (EXIT_SUCCESS); } int by_size(const void * a, const void * b) { struct block *ia = (struct block *)a; struct block *ib = (struct block *)b; return (int)(ia->size - ib->size); } int by_address(const void * a, const void * b) { struct block *ia = (struct block *)a; struct block *ib = (struct block *)b; return (void *)ia->ptr > (void *)ib->ptr; } Sample output: No. Address Size 0 167530504 5211 1 167551352 21530 2 167637480 18456 3 167711312 28624 <...> 266 3071238152 36159 267 3071651848 33333 268 3073114120 204799 269 3073937416 794617 I tried to plot this data with gnuplot, but it'll require parting data at two or more parts because of big address range. --90e6ba53a940665edc04a4e6af1d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Fri, Apr 29, 2011 at 12:42 PM, Solar = Designer <solar@= openwall.com> wrote:
JIghtuse -

On Wed, Apr 27, 2011 at 10:24:15AM +0700, JIghtuse wrote:
> So, I am still working on testing malloc() of musl. My coding breaks b= y
> some increase of studing in university, but I have to say I want to > participate. Is it real to join Summer of Security?

Sure. =A0Thanks for the status update.

> After finished musl tests

Luka is the primary person to work on these, but you're welcome to stay=
involved as well - e.g., you may help test Luka's tests against more libc's, report problems in here (both those of the tests and of the
libc's), and improve the tests.

> I want to try blists development also.

Sounds good. =A0This is off-topic for the musl list, though, so pleas= e
e-mail me off-list for it when you're ready.

Thanks,

Alexander

P.S. Somehow you started a new thread instead of posting to the existing thread with the same Subject. =A0You should have used "reply" on = a message
in the proper thread.

So, my program creates array of structures of memory= blocks and works with it.
Source code:

#include <stdio.h><= br>#include <stdlib.h>
#include <string.h>
#include <s= trings.h>

#define M 100000000
#define REPEATS 10

struct block {
=A0= =A0=A0 unsigned int* ptr;
=A0=A0=A0 unsigned int size;
} blocks[M / 1= 00];

int by_size(const void *, const void *);
int by_address(cons= t void *, const void *);

int main(int argc, char *argv[])
{
=A0=A0=A0 unsigned int i =3D 0= , j, counter;
=A0=A0=A0 unsigned int seed;
=A0=A0=A0 unsigned int amo= unt =3D 0;
=A0=A0=A0 unsigned int size;
=A0=A0=A0
=A0=A0=A0 if (a= rgc > 1) {
=A0=A0=A0 =A0=A0=A0 seed =3D atoi(argv[1]);
=A0=A0=A0 } else {
=A0=A0=A0 =A0=A0=A0 printf("Type seed: ");<= br>=A0=A0=A0 =A0=A0=A0 scanf("%u", &seed);
=A0=A0=A0 }
=
=A0=A0=A0 bzero(blocks, sizeof(blocks[0]) * (M / 100));

=A0=A0= =A0 for (counter =3D 0; counter < REPEATS; counter++) {
=A0=A0=A0 =A0=A0=A0 while (amount < M) {
=A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 size =3D rand() % (M / 100);
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 if (size = > 100000) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 size |=3D 0xff0;<= br>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }

=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 blo= cks[i].size =3D size;
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 blocks[i].ptr =3D ma= lloc(sizeof(int) * size);
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 if (blocks[i].ptr =3D=3D NULL) {
=A0=A0=A0= =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 printf("\nmalloc() error!\n");
= =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 exit(EXIT_FAILURE);
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 amount +=3D blocks[i= ].size;
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 i++;
=A0=A0=A0 =A0=A0=A0 }

=A0=A0=A0 =A0=A0=A0 if (counter !=3D REPEATS -= 1) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 qsort(blocks, i, sizeof(struct block= ), by_size);
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 for (j =3D i / 4; j < i; j= ++) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 amount -=3D blocks[j].size= ;
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 free(blocks[j].ptr);
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 bzero((voi= d *)(blocks + i / 4), sizeof(blocks[0]) * ((i / 4) * 3 + 3));
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 i /=3D 4;
=A0=A0=A0 =A0=A0=A0 } else {
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 qsort(blocks, i, sizeof(struct block), by_address);
= =A0=A0=A0 =A0=A0=A0 }=A0=A0=A0
=A0=A0=A0 }
=A0=A0=A0
=A0=A0=A0 printf("%5s %12s %8s\n", &= quot;No.", "Address", "Size");
=A0=A0=A0 for (j= =3D 0; j < i - 1; j++) {
=A0=A0=A0 =A0=A0=A0 printf("%5u %12u %= 8u\n", j, (unsigned int)blocks[j].ptr, blocks[j].size);
=A0=A0=A0 =A0=A0=A0 if (blocks[j].ptr + blocks[j].size >=3D blocks[j + 1= ].ptr) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 printf("\nOverlaped!\n"= );
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 exit(EXIT_SUCCESS);
=A0=A0=A0 =A0=A0= =A0 }
=A0=A0=A0 }
=A0=A0=A0 printf("%5u %12u %8u\n", j, (un= signed int)blocks[j].ptr, blocks[j].size);
=A0=A0=A0 exit (EXIT_SUCCESS);
}

int by_size(const void * a, cons= t void * b)
{
=A0 struct block *ia =3D (struct block *)a;
=A0 stru= ct block *ib =3D (struct block *)b;
=A0 return (int)(ia->size - ib-&g= t;size);
}

int by_address(const void * a, const void * b)
{
=A0=A0=A0 s= truct block *ia =3D (struct block *)a;
=A0=A0=A0 struct block *ib =3D (s= truct block *)b;
=A0=A0=A0 return (void *)ia->ptr > (void *)ib->= ;ptr;
}




Sample output:
=A0 No.=A0=A0=A0=A0=A0 Address=A0=A0=A0=A0 Si= ze
=A0=A0=A0 0=A0=A0=A0 167530504=A0=A0=A0=A0 5211
=A0=A0=A0 1=A0=A0= =A0 167551352=A0=A0=A0 21530
=A0=A0=A0 2=A0=A0=A0 167637480=A0=A0=A0 184= 56
=A0=A0=A0 3=A0=A0=A0 167711312=A0=A0=A0 28624
<...>
=A0 2= 66=A0=A0 3071238152=A0=A0=A0 36159
=A0 267=A0=A0 3071651848=A0=A0=A0 33333
=A0 268=A0=A0 3073114120=A0=A0 2= 04799
=A0 269=A0=A0 3073937416=A0=A0 794617


I tried to plot t= his data with gnuplot, but it'll require parting data at two or more pa= rts because of big address range.
--90e6ba53a940665edc04a4e6af1d--