Article View: gnu.g++.bug
Article #2056new and delete bug report 2
From: "Naoki Saito Ext. 5471", GEO-002
Date: Tue, 30 May 1989 21:16
Date: Tue, 30 May 1989 21:16
97 lines
2598 bytes
2598 bytes
Hi, everyone! There's a bug in new and delete in g++-1.34.2 on Sun3
OS 4.0.1. I reported this before, but I confirmed this bug by simpler
examples. Please try these examples on your machines and let me know
what happens. Program (1) does produce out of memory error. (2) does not
produce any error.
(1) Error stuff.
=====================cut here===============================================
// newtest.cc
#include <stream.h>
#include <math.h>
main()
{
float array[100];
float window[100];
float *res, *product(float*, float*);
int i;
for (i = 0; i < 100; i++)
{
array[i] = (float)i;
window[i] = cos(M_PI*(i-50)/100);
}
for (i = 0; i < 1000000; i++)
{
res = product(array, window);
delete[100] res;
}
exit(0);
}
float *product(float* array, float* window)
{
int i;
float* temp = new float[100];
for (i = 0; i < 100; i++)
temp[i] = array[i]*window[i];
return temp;
}
==============================================================================
(2) The following program which basically replaces new and delete to malloc
and free works fine without any error.
=====================cut here=================================================
// newtest2.cc
#include <stdio.h>
#include <math.h>
main()
{
float array[100];
float window[100];
float *res, *product(float*, float*);
int i;
for (i = 0; i < 100; i++)
{
array[i] = (float)i;
window[i] = cos(M_PI*(i-50)/100);
}
for (i = 0; i < 1000000; i++)
{
res = product(array, window);
free(res);
}
exit(0);
}
float *product(float* array, float* window)
{
float *temp;
int i;
temp = (float*) malloc(sizeof(float)*100);
for (i = 0; i < 100; i++)
temp[i] = array[i]*window[i];
return temp;
}
==============================================================================
Both of them were compiled with
$ g++ -g -O -m68881 -o newtest newtest.cc -lg++ -lm
style.
Does g++-1.35.* on Sun3 OS 4.0.1 produce the same bug?
Thank you very much,
Naoki Saito (saito@sdr.slb.com)
Schlumberger-Doll Research
Technical Details
Message-ID:
<8905302141.AA13478@life.ai.mit.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!sdr.slb.com!SAITOShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!sdr.slb.com!SAITO
From: SAITO@sdr.slb.com ("Naoki Saito Ext. 5471", GEO-002)
Newsgroups: gnu.g++.bug
Subject: new and delete bug report 2
Message-ID: <8905302141.AA13478@life.ai.mit.edu>
Date: 30 May 89 21:16:00 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 97