【问题标题】:valgrind give error when printing the second line to filevalgrind 在将第二行打印到文件时给出错误
【发布时间】:2013-05-14 12:46:49
【问题描述】:

我正在使用 valgrind 来查找我的代码中的错误。我使用的命令是

 valgrind --leak-check=yes ./a.out

我只用-g 代码编译代码。我收到许多指向单个写入行的错误(三个打印值已初始化且定义明确)。

write (22,*) avlength, stdlength, avenergy

全部带有Conditional jump or move depends on uninitialised value(s) 错误。所述行是从一堆行打印到单个文件的第二行。在错误结束时,我又得到了两个,一个指向打开文件的行

resStep = int(conf*100/iterate)
               if (resStep.lt.10) then
                  write (resFile, "(A5,I1)") "res00",resStep
               elseif (ResStep.lt.100) then
                  write (resFile, "(A4,I2)") "res0",resStep
               else 
                  write (resFile, "(A3,I1)") "res",resStep
               endif
               open (unit=22,file=trim(resFile),status='replace', 
     c                 action='write')

resStep 是整数。错误是Syscall param write(buf) points to uninitialised byte(s)。最后,当我刷新文件时(在关闭它之前),我收到一个错误Address 0x52d83f4 is 212 bytes inside a block of size 8,344 alloc'd

我在这里找不到任何逻辑。如果问题在于以错误的方式打开文件,我不会在第一行得到错误吗?

我使用 f95 编译它,我的 gcc 版本是 4.1.2。我什么都升级不了。

【问题讨论】:

    标签: valgrind system-calls writetofile fortran95


    【解决方案1】:

    猜测:检查resFile的数据类型。是字符串还是单元号?

    我的 Fortran 95 已经生锈了,但请尝试在调用 write() 之前将调用移动到 open() 并传递一个整数 resUnit 而不是 resFile 作为 write() 的第一个参数:

    CHARACTER(LEN=20):: resFile
    INTEGER(KIND=2)  :: resUnit, resStep
    
    resStep = 1
    resFile = 'MY-results'
    resUnit = 22
    open (unit=resUnit, file=trim(resFile), status='replace', action='write')
    write(resUnit, "(A5,I1)") "res00", resStep
    
    END
    

    【讨论】:

    • 字符 (len=20):: resFile.我的 fortran Foo 真的很差。我正在根据需要更新教授代码。
    • @Yotam,尝试在 write() 之前移动 open() 并将一个单位而不是字符 (len=20) 传递给 open()。我已经用一个简短的独立程序更新了我的答案。
    猜你喜欢
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 2020-06-23
    • 2022-06-14
    相关资源
    最近更新 更多