Skip to contentSkip to conversation

A rather special bug?

DISCUSSION Stephan Brauss 1 participant 1 message Mar 25, 2003

lore
Share & tools
lore
#0 lore raw

Hello!

I think that I have found a bug that is present at least in dosemu-1.0.2. Compile the appended program, run it and press any key while the memory testing loop is running. You will see that one byte of the allocated memory blocks is altered and now contains the ascii code of the pressed character. Can someone reproduce this problem? Is it fixed in newer dosemu versions?

Stephan

----------------------

#include <stdio.h>
#include <stdlib.h>

#define SEGMENTS 7
#define SIZE 65500

int *segments[SEGMENTS];

int main()

{
	int i,j,k;

	for(i=0;i<SEGMENTS;i++)
	{
		printf("malloc segment %d\n",i+1);
		segments[i]=(int *)malloc(SIZE);
		if(segments[i]==NULL)
		{
			printf("malloc error\n");
			exit(1);
		}
		for(j=0;j<SIZE/sizeof(int);j++)
			segments[i][j]=0;
	}

	k=1;
	for(;;)
	{
		printf("loop: %d\n",k);
		for(i=0;i<SEGMENTS;i++)
		{
			for(j=0;j<SIZE/sizeof(int);j++)
			{
				if(segments[i][j]!=0)
				{
					printf("segments[%d][%d]=%d\n",i,j,segments[i][j]);
				}
			}
		}
		k++;
	}
	return 0;
}