在 SFML 项目中加载字体时出现 Valgrind 错误

问题描述 投票:0回答:1

此代码:

// g++ sfml.cpp -o sfml_test -lsfml-graphics -lsfml-window -lsfml-system
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::Font font;
    if (!font.loadFromFile("font.ttf"))
    {
        std::cout << "ruh oh" << std::endl;
    }

    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

    return 0;
}

...导致 valgrind 从两个上下文报告两个相同的错误:

valgrind ./sfml_test
==7557==  Invalid read of size 8
==7557==    at 0x401D734: strncmp (strcmp.S:175)
==7557==    by 0x400604D: is_dst (dl-load.c:209)
==7557==    by 0x4008566: _dl_dst_count (dl-load.c:246)
==7557==    by 0x4008757: expand_dynamic_string_token (dl-load.c:388)
==7557==    by 0x40088D1: fillin_rpath.isra.0 (dl-load.c:460)
==7557==    by 0x4008BE1: decompose_rpath (dl-load.c:631)
==7557==    by 0x4009745: cache_rpath (dl-load.c:673)
==7557==    by 0x4009745: cache_rpath (dl-load.c:654)
==7557==    by 0x4009745: _dl_map_object (dl-load.c:2074)
==7557==    by 0x400DDC0: openaux (dl-deps.c:64)
==7557==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==7557==    by 0x400E138: _dl_map_object_deps (dl-deps.c:248)
==7557==    by 0x4013DAA: dl_open_worker (dl-open.c:571)
==7557==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==7557==  Address 0x5a25719 is 9 bytes inside a block of size 15 alloc'd
==7557==    at 0x483877F: malloc (vg_replace_malloc.c:307)
==7557==    by 0x401C29A: strdup (strdup.c:42)
==7557==    by 0x4008B74: decompose_rpath (dl-load.c:606)
==7557==    by 0x4009745: cache_rpath (dl-load.c:673)
==7557==    by 0x4009745: cache_rpath (dl-load.c:654)
==7557==    by 0x4009745: _dl_map_object (dl-load.c:2074)
==7557==    by 0x400DDC0: openaux (dl-deps.c:64)
==7557==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==7557==    by 0x400E138: _dl_map_object_deps (dl-deps.c:248)
==7557==    by 0x4013DAA: dl_open_worker (dl-open.c:571)
==7557==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==7557==    by 0x40138F9: _dl_open (dl-open.c:837)
==7557==    by 0x545C257: dlopen_doit (dlopen.c:66)
==7557==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)

当删除五个字体加载行时,valgrind 不会报告任何错误。字体文件位于可执行文件 sfml_test 旁边。

无论错误如何,程序都会正确执行,并且字体已加载并可用。关于如何消除 valgrind 错误有什么想法吗?

我在 Linux 上,不记得如何安装 SFML。我可能刚刚跑过:

sudo apt-get install libsfml-dev

我无法找到检查我的 SFML 版本的方法,但它将是 2.5/2.6。

我的操作系统是 PureOS 版本 10(debian fork),我的 g++ 版本是(Debian 10.2.1-6)10.2.1 20210110(如果这有意义的话),我的 glibc 版本是 2.31。

完整的 valgrind 输出是:

==11908== Memcheck, a memory error detector
==11908== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==11908== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==11908== Command: ./sfml_test
==11908== 
==11908== Invalid read of size 8
==11908==    at 0x401D734: strncmp (strcmp.S:175)
==11908==    by 0x400604D: is_dst (dl-load.c:209)
==11908==    by 0x4008566: _dl_dst_count (dl-load.c:246)
==11908==    by 0x4008757: expand_dynamic_string_token (dl-load.c:388)
==11908==    by 0x40088D1: fillin_rpath.isra.0 (dl-load.c:460)
==11908==    by 0x4008BE1: decompose_rpath (dl-load.c:631)
==11908==    by 0x4009745: cache_rpath (dl-load.c:673)
==11908==    by 0x4009745: cache_rpath (dl-load.c:654)
==11908==    by 0x4009745: _dl_map_object (dl-load.c:2074)
==11908==    by 0x400DDC0: openaux (dl-deps.c:64)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908==    by 0x400E138: _dl_map_object_deps (dl-deps.c:248)
==11908==    by 0x4013DAA: dl_open_worker (dl-open.c:571)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908==  Address 0x5a25719 is 9 bytes inside a block of size 15 alloc'd
==11908==    at 0x483877F: malloc (vg_replace_malloc.c:307)
==11908==    by 0x401C29A: strdup (strdup.c:42)
==11908==    by 0x4008B74: decompose_rpath (dl-load.c:606)
==11908==    by 0x4009745: cache_rpath (dl-load.c:673)
==11908==    by 0x4009745: cache_rpath (dl-load.c:654)
==11908==    by 0x4009745: _dl_map_object (dl-load.c:2074)
==11908==    by 0x400DDC0: openaux (dl-deps.c:64)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908==    by 0x400E138: _dl_map_object_deps (dl-deps.c:248)
==11908==    by 0x4013DAA: dl_open_worker (dl-open.c:571)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908==    by 0x40138F9: _dl_open (dl-open.c:837)
==11908==    by 0x545C257: dlopen_doit (dlopen.c:66)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908== 
==11908== Invalid read of size 8
==11908==    at 0x401D734: strncmp (strcmp.S:175)
==11908==    by 0x400604D: is_dst (dl-load.c:209)
==11908==    by 0x400861E: _dl_dst_substitute (dl-load.c:288)
==11908==    by 0x40088D1: fillin_rpath.isra.0 (dl-load.c:460)
==11908==    by 0x4008BE1: decompose_rpath (dl-load.c:631)
==11908==    by 0x4009745: cache_rpath (dl-load.c:673)
==11908==    by 0x4009745: cache_rpath (dl-load.c:654)
==11908==    by 0x4009745: _dl_map_object (dl-load.c:2074)
==11908==    by 0x400DDC0: openaux (dl-deps.c:64)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908==    by 0x400E138: _dl_map_object_deps (dl-deps.c:248)
==11908==    by 0x4013DAA: dl_open_worker (dl-open.c:571)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908==    by 0x40138F9: _dl_open (dl-open.c:837)
==11908==  Address 0x5a25719 is 9 bytes inside a block of size 15 alloc'd
==11908==    at 0x483877F: malloc (vg_replace_malloc.c:307)
==11908==    by 0x401C29A: strdup (strdup.c:42)
==11908==    by 0x4008B74: decompose_rpath (dl-load.c:606)
==11908==    by 0x4009745: cache_rpath (dl-load.c:673)
==11908==    by 0x4009745: cache_rpath (dl-load.c:654)
==11908==    by 0x4009745: _dl_map_object (dl-load.c:2074)
==11908==    by 0x400DDC0: openaux (dl-deps.c:64)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908==    by 0x400E138: _dl_map_object_deps (dl-deps.c:248)
==11908==    by 0x4013DAA: dl_open_worker (dl-open.c:571)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908==    by 0x40138F9: _dl_open (dl-open.c:837)
==11908==    by 0x545C257: dlopen_doit (dlopen.c:66)
==11908==    by 0x4C0CACF: _dl_catch_exception (dl-error-skeleton.c:208)
==11908== 
==11908== 
==11908== HEAP SUMMARY:
==11908==     in use at exit: 199,041 bytes in 2,589 blocks
==11908==   total heap usage: 28,778 allocs, 26,189 frees, 8,662,565 bytes allocated
==11908== 
==11908== LEAK SUMMARY:
==11908==    definitely lost: 0 bytes in 0 blocks
==11908==    indirectly lost: 0 bytes in 0 blocks
==11908==      possibly lost: 0 bytes in 0 blocks
==11908==    still reachable: 199,041 bytes in 2,589 blocks
==11908==         suppressed: 0 bytes in 0 blocks
==11908== Rerun with --leak-check=full to see details of leaked memory
==11908== 
==11908== For lists of detected and suppressed errors, rerun with: -s
==11908== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
c++ valgrind sfml
1个回答
0
投票
==7557==    at 0x401D734: strncmp (strcmp.S:175)

Memcheck 应该重定向 strncmp。如果不是,那么要么您使用的是旧版本的 Valgrind(最有可能),要么您使用的 libc 具有 Valgrind 无法检测到的

strncmp
(不太可能)。

请勿为此使用抑制。

尝试使用最新版本的 Valgrind。

© www.soinside.com 2019 - 2024. All rights reserved.