stack corruption

I

ifoundgoldbug

Ok here is a short description of what i am doing. I need to program
a dll for use by another program. the dll compiles fine but when i
call it from another program i get a stack corruption of the array in
the gamma section of the dll. so below i will post the code for in
order:

my dll header
my dll cpp

my testprogram header
my testprogram cpp

ANY help on this would be fantastic.


my dll header

#ifndef EICKEMEIER_INCLUDE
#define EICKEMEIER_INCLUDE
double Eickemeier(int x, int y, double xc, double yc, double volc,
double sig, double del, double zu, double zo, double b, double a);
#endif



my dll cpp

#include <math.h>
#include <iostream>
#include <stdexcept>


using namespace std;


long double gammafcn( double x)
{
long double tmp, ser, stp, temp;
int j;
long double cof[6];

stp = 2.50662827465;

cof[1] = 76.18009173;
cof[2] = -86.50532033;
cof[3] = 24.01409822;
cof[4] = -1.231739516;
cof[5] = 0.00120858003;
cof[6] = -0.00000536382;

x = x - 1;
tmp = x + 5.5;
tmp = (x + 0.5) * log(tmp) - tmp;
ser = 1;

for (j=1; j<7; j++)
{
x = x + 1;
ser = ser + cof[j] / x;
}

temp =(exp(tmp + log(stp * ser)));
return temp;
}


double Eickemeier(int x, int y, double xc, double yc, double volc,
double sig, double del, double zu, double zo, double b, double a)
{
double Rz, rx, fr, eick, temp;
long double gamma;

Rz = pow(zu * zo , 0.5) * (1 / tan(b * 3.14159265 / 180));
rx = pow((pow((x - xc) , 2) + pow((y - yc) , 2)), 0.5);

temp =2 / del;


gamma = gammafcn(temp);

fr = (sig * del) / (pow(2 * 3.14159265 , (1 - (2 / del))) *
pow(Rz , 2) * gamma) * exp(-3.14159265 * pow(sig , (del /
2)) * pow(rx / Rz , del));

eick = a * fr * volc;

return (eick);
}


my testprogram header

#pragma once

#include "resource.h"


my testprogram cpp

#include "eickDll.h"
#include "stdafx.h"
#include "testfile.h"
#include <iostream>

double Eickemeier();


using namespace std;

int main()
{
double x;

x = Eickemeier(0, 0, 0, 0, 2000000, 1, 2, 505, 5, 30, 1);

cout << x;
cin >> x;

return 0;
}
 
V

Victor Bazarov

[..]
long double cof[6];
[..]
cof[1] = 76.18009173;
cof[2] = -86.50532033;
cof[3] = 24.01409822;
cof[4] = -1.231739516;
cof[5] = 0.00120858003;
cof[6] = -0.00000536382;

In C++ an array of 6 elements has indices from 0 through 5.

V
 
I

ifoundgoldbug

Changed the indecies (i feel silly for missing that) but the same
problem persists.
 
I

ifoundgoldbug

i also changed the for loop accordingly. the error crops up before the
gamma function is even called.
 
G

Gianni Mariani

long double gammafcn( double x)
{ .....

for (j=1; j<7; j++)
{
x = x + 1;
ser = ser + cof[j] / x;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Still have a problem here.
 
I

ifoundgoldbug

Apologies for not following proper posting etiquette.

compiler name, version number, operating system.
visual studio .net 2003 sp1 windows xp

libraries, exact compiler and linker options.
libs = math.h, iostream,
compiler is visual studio 2003
linker options = visual studio defualt

exact messages received.
run time check failure #2 - Stack around the variable of 'cof' was
corrupted

also i am having trouble finding the error in my for statement that
Gianni Mariani mentioned. I have never worked down at the stack level
before so please forgive my slow pace at picking things up.
 
V

Victor Bazarov

Apologies for not following proper posting etiquette.

compiler name, version number, operating system.
visual studio .net 2003 sp1 windows xp

Only matters if you seek a confirmation that it's a bug in that
compiler. We generally don't discuss compilers here.
libraries, exact compiler and linker options.
libs = math.h, iostream,

Those are not "libs". They are _headers_. Options don't matter.
compiler is visual studio 2003
linker options = visual studio defualt

exact messages received.
run time check failure #2 - Stack around the variable of 'cof' was
corrupted

That's not a message from the compiler. That's from your execution
environment. Please learn to debug your program.
also i am having trouble finding the error in my for statement that
Gianni Mariani mentioned. I have never worked down at the stack level
before so please forgive my slow pace at picking things up.

You don't need to "work down at the stack level" if you write correct
C++ code. Again, post your *code*, and we will try to help. If you
are confused about how and what to post, try looking at other people's
posts. See what they posted, what information they provided, and
follow any good example you'll find.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top