2013-09-27 65 views
-1

下面是當我在Valgrind的運行我的代碼Valgrind的 - 錯誤

1)未初始化值由堆棧分配 ==在0x400EC1 16808 ==創建我得到的消息:的init()(Hite.cpp: 90)

2)大小的無效讀8

xmin=0.000000, xmax=1.000000, dx=0.010000, dt=0.000208, c=3.000000 
==2763== Conditional jump or move depends on uninitialised value(s) 
==2763== at 0x3E5420E836: __ieee754_exp (in /lib64/libm-2.12.so) 
==2763== by 0x3E54224A81: exp (in /lib64/libm-2.12.so) 
==2763== by 0x400F88: init() (Hite.cpp:96) 
==2763== by 0x4010C8: main (Hite.cpp:114) 
==2763== Uninitialised value was created by a stack allocation 
==2763== at 0x400EC1: init() (Hite.cpp:90) 
==2763== 
==2763== Use of uninitialised value of size 8 
==2763== at 0x3E5420E8EC: __ieee754_exp (in /lib64/libm-2.12.so) 
==2763== by 0x3E54224A81: exp (in /lib64/libm-2.12.so) 
==2763== by 0x400F88: init() (Hite.cpp:96) 
==2763== by 0x4010C8: main (Hite.cpp:114) 
==2763== Uninitialised value was created by a stack allocation 
==2763== at 0x400EC1: init() (Hite.cpp:90) 

我們如何從上而產生

90 void init() { 
91   double xmin=0; 
92  double xavg = 0.5*(xmin+xmax); 


int main(int argc,char **argv) { 
112  printf("xmin=%f, xmax=%f, dx=%f, dt=%f, c=%f\n", 
113      xmin=0,xmax=0,dx=0,dt=0,c=0); 
114  init() 
來這些錯誤

;

+0

你可以在Hite.cpp周圍顯示行:90? – Grzegorz

+0

請更多代碼,沒有足夠的信息來說明問題所在。 – john

+0

您是否從函數返回值? –

回答

1

這將有助於看到的代碼,但是從它的外觀所創建的堆棧上未初始化的對象:

double val; 

你應該改變它是

double val = double(); 

double val(0); 

(我假設爲double根據大小;它也可以是long long或某種其他類型的尺寸8)。

+0

我在init() – user2588812

+0

@ user2588812處得到第一個錯誤:您能顯示導致問題的代碼嗎? –

+0

更新請檢查主帖 – user2588812