相关疑难解决方法(0)

未初始化的值由堆栈分配创建

我使用Valgrind工具调试了我的代码.它在此功能中显示此错误.我在下面给出了错误和我的功能.我不知道这里有什么问题?我怎样才能纠正它?我的错误是.

未初始化的值是由0x80996D7处的堆栈分配创建的:cdtojd(std :: string const&)

我的代码是.

double cdtojd(const string &cdate);

double cdtojd(const string &cdate)
{
    int dd,mm,yy;
    int y,m;
    double jd=0;

    //mm = atoi(cdate.substr(0,2).c_str());
    //dd = atoi(cdate.substr(2,2).c_str());
    //yy = atoi(cdate.substr(4,4).c_str());

    sscanf(cdate.c_str(),"%2d%2d%4d",&mm,&dd,&yy);

    //cout<<mm<<"..."<<dd<<"...."<<yy<<endl;

    y = (yy - 1900) * 372;

    m = (mm-1) * 31;

    jd = dd + m + y;

    return jd;
}
Run Code Online (Sandbox Code Playgroud)

c++ valgrind

8
推荐指数
1
解决办法
9666
查看次数

未初始化的值由堆栈分配创建

==13890== Conditional jump or move depends on uninitialised value(s)
==13890==    at 0x4E7E4F1: vfprintf (vfprintf.c:1629)
==13890==    by 0x4E878D8: printf (printf.c:35)
==13890==    by 0x400729: main (001.c:30)
==13890==  Uninitialised value was created by a stack allocation
==13890==    at 0x400617: main (001.c:11)
Run Code Online (Sandbox Code Playgroud)

引用的行:

int limit = atoi(argv[1]);
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决它.我试过在stackoverflow和谷歌搜索,但我找不到解决方案.

代码(来自修订历史):

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

int main(int argc, char *argv[])
{
    if (argc != 2) {
        printf("You must pass a single integer\n");
        exit(1);
    }

    int limit = atoi(argv[1]); 
    int numbers[limit / 2];
    int count = 0; …
Run Code Online (Sandbox Code Playgroud)

c valgrind

4
推荐指数
1
解决办法
2万
查看次数

未初始化的值是由堆栈分配创建的 - valgrind

我用valgrind用选项调试我的代码track-origins=yes并遇到了这个错误.

$ valgrind --track-origins=yes ./frgtnlng < in > out
==7098== 
==7098== Conditional jump or move depends on uninitialised value(s)
==7098==    at 0x4C2F1BC: strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7098==    by 0x400857: main (frgtnlng.c:24)
==7098==  Uninitialised value was created by a stack allocation
==7098==    at 0x40064C: main (frgtnlng.c:9)
==7098== 
==7098== Conditional jump or move depends on uninitialised value(s)
==7098==    at 0x40085A: main (frgtnlng.c:24)
==7098==  Uninitialised value was created by a stack allocation
==7098==    at 0x40064C: main (frgtnlng.c:9)
Run Code Online (Sandbox Code Playgroud)

第9行是:

scanf("%d", &t);
Run Code Online (Sandbox Code Playgroud)

我不明白这是如何导致问题的.

frgtnlng.c: …

c valgrind

0
推荐指数
1
解决办法
3524
查看次数

标签 统计

valgrind ×3

c ×2

c++ ×1