- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
==11136== Invalid read of size 8
==11136== at 0x5AFC696: memrchr (memrchr.S:289)
==11136== by 0x5B57FAF: dirname (dirname.c:45)
==11136== by 0x405F43: push::lg_cmd_dirname(push::Env&) (LGExtension.cpp:379)
==11136== by 0x42533C: push::Instruction::operator()(push::Env&) const (in /home/bots/svn/eco/branches/skynet_BigPUSH/src/push3.0/extension/push_bloodline)
==11136== by 0x488ECD: push::Env::go(int) (Env.cpp:72)
==11136== by 0x4A84D5: main (bloodline.cpp:99)
==11136== Address 0x640daf8 is 8 bytes inside a block of size 10 alloc'd
==11136== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11136== by 0x5AEF801: strdup (strdup.c:43)
==11136== by 0x405EF2: push::lg_cmd_dirname(push::Env&) (LGExtension.cpp:369)
==11136== by 0x42533C: push::Instruction::operator()(push::Env&) const (in /home/bots/svn/eco/branches/skynet_BigPUSH/src/push3.0/extension/push_bloodline)
==11136== by 0x488ECD: push::Env::go(int) (Env.cpp:72)
==11136== by 0x4A84D5: main (bloodline.cpp:99)
==11136==
这是合法的错误吗?看起来读取发生在有效 block 内。在我的程序中,调用如下所示:
char *path = strdup(full_path.c_str());
cerr << "Path is : " << path << endl;
result = dirname(path);
if(result < 0){
cerr << "Dirname failed for some reason. Check log." << endl;
}
错误发生时 cerr 的输出是:
Path is : /tmp/tmp/
这是一个有效的路径。 Dirname 对此应该没有任何问题,并且它在堆分配的拷贝上运行。
编辑:
这是一个会产生此错误的最小示例:
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <libgen.h>
int main(){
char *path = strdup("/tmp/tmp/");
char* result = dirname(path);
std::cerr << result << std::endl;
}
用 g++ 编译。
运行 valgrind,你会得到:
==32466== Memcheck, a memory error detector
==32466== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==32466== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==32466== Command: ./a.out
==32466==
==32466== Invalid read of size 8
==32466== at 0x51C7696: memrchr (memrchr.S:289)
==32466== by 0x5222FAF: dirname (dirname.c:45)
==32466== by 0x400865: main (in /home/j3doucet/a.out)
==32466== Address 0x59ff048 is 8 bytes inside a block of size 10 alloc'd
==32466== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32466== by 0x51BA801: strdup (strdup.c:43)
==32466== by 0x400855: main (in /home/j3doucet/a.out)
==32466==
/tmp
==32466==
==32466== HEAP SUMMARY:
==32466== in use at exit: 10 bytes in 1 blocks
==32466== total heap usage: 1 allocs, 0 frees, 10 bytes allocated
==32466==
==32466== LEAK SUMMARY:
==32466== definitely lost: 10 bytes in 1 blocks
==32466== indirectly lost: 0 bytes in 0 blocks
==32466== possibly lost: 0 bytes in 0 blocks
==32466== still reachable: 0 bytes in 0 blocks
==32466== suppressed: 0 bytes in 0 blocks
==32466== Rerun with --leak-check=full to see details of leaked memory
==32466==
==32466== For counts of detected and suppressed errors, rerun with: -v
==32466== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
最佳答案
Valgrind 指示大小为 8 的读取是从中的字节 nr 8 完成的一个 10 字节的 block 。此读取由 memrchr 完成。此类功能通常基于您可以阅读的假设进行优化比分配的 block 更多的字节。为避免报告此类问题,Valgrind 必须更换此类优化通过其自身的重新定义功能发挥作用。
memrchr 仅在 Valgrind 3.8 及更高版本中被重新定义。
=> 您应该使用最新版本的 Valgrind (3.8.1) 重试。然后可能不再报告错误(假设它实际上是误报由于未重新定义 memrchr)。
关于c++ - Valgrind 与 dirname 决裂?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12708501/
在 Win7 上使用 ruby 2.0.0p481 (2014-05-08) [x64-mingw32] 在一个目录中(准确地说是d:\download\ruby)我有两个文件——calling.
我总是用 tar czf file.tar.gz dirname而不是 tar -czf file.tar.gz dirname (没有 - )因为更快 我知道......从文档中,我所做的是错误的。
我是 Django 项目的初学者。Django 项目的 settings.py 文件包含这两行: BASE_DIR = os.path.dirname(os.path.dirname(os.path.
我正在尝试实现一个 perl 脚本,我需要获取我执行的文件的目录。 例如,如果我正在执行的文件位于 C:\Scripts\MyScript.pl我想得到 C:\Scripts . 我试过 dirnam
我有一个名为 abc.sh 的简单脚本,如下所示,用于设置环境变量 #!/bin/bash sourcePath () { filename=`basename $0` current_dir="./
我有很多这样的文件: ./1/wwuhw.mp3 ./2/nweiewe.mp3 ./3/iwqjoiw.mp3 ./4/ncionw.MP3 ./5/joiwqfm.wmv ./6/jqoifiew
考虑以下经典问题案例:
__FILE__表示当前所在文件的绝对路径包括文件名,dirname(__FILE__)表示当前文件的绝对路径,basename(__FILE__)表示当前文件的文件名称,dirname(__FIL
__FILE__表示当前所在文件的绝对路径包括文件名,dirname(__FILE__)表示当前文件的绝对路径,basename(__FILE__)表示当前文件的文件名称,dirname(__FIL
我的基本目录中有一个配置文件,我正在尝试确定用于文件包含的目录的绝对路径。但是 Windows 在路径中使用反斜杠。 define( 'ABSOLUTE_PATH', dirname(__FILE__
编写脚本来优化我的网络图片。名称中包含空格的文件名和目录有问题。 这是我所拥有的: read -p "Enter full path from root (/) to your site... exa
dirname() 真的很糟糕,因为它修改了参数,因此它需要原始字符串的另一个难看的副本。所以请不要使用 dirname()。 有没有类似的功能,但又可以安全使用? 最佳答案 编辑:修复我愚蠢时的可怕
我想知道为什么以下代码在修改作为 dirname() 结果的字符串文字时不会抛出段错误,但在修改通常创建的字符串文字时会抛出段错误: #include #include #include #de
我想从 .bat 文件中获取文件的父目录。因此,如果变量设置为 "C:\MyDir\MyFile.txt",我想获取 "C:\MyDir"。换句话说,相当于典型 UNIX 环境中的 dirname()
看一下代码 $link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; echo dirname(dirname($link)); 问题 1.
我使用 Ruby 1.9.3 编写了一些用于系统管理的小 Ruby 脚本。在我使用的一个脚本中: File.dirname(__FILE__) 获取脚本文件的目录。这将返回一个相对路径,但是当我从第二
dirname(dirname(_FILE_)); 假设__FILE__为 /home/web/config/config.php 上面的方法输出为 /home/web dirname(
PHP 常量 dirname(__file__) __FILE__ :被称为PHP魔术常量 ,返回当前执行PHP脚本的完整路径和文件名,包含一个绝对路径 1)dirname(__FILE__)
我正在练习用 php 编写代码并学习 php 语法。我对以下功能有点困惑: function __construct() { require_once dirname(__FILE__) .
目前我不明白,为什么 python os.path.dirname 的行为如此。 假设我有以下脚本: # Not part of the script, just for the current sa
我是一名优秀的程序员,十分优秀!