https://bugs.kde.org/show_bug.cgi?id=492549

            Bug ID: 492549
           Summary: std::string::find(char) breaks with massif
    Classification: Developer tools
           Product: valgrind
           Version: 3.19.0
          Platform: RedHat Enterprise Linux
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: massif
          Assignee: n...@valgrind.org
          Reporter: martin.lu...@ohb.de
  Target Milestone: ---

SUMMARY

valgrind --tool=massif produces wrong behaviour in C++ std::string::find(char)


STEPS TO REPRODUCE

Create a file eg test.cpp with the following content:

#include <string>
#include <iostream>
int main()
{
    std::string s = "haystack";
    std::cout << s.find('x', 0) << std::endl;
    std::cout << s.find("x", 0) << std::endl;
}

Compile it: g++ test.cpp

Run it as follows:
./a.out
valgrind ./a.out
valgrind --tool=massif ./a.out



OBSERVED RESULT
We expect std::string::npos aka the unsigned interpretation of -1, because the
character is not contained in the string.
But if massif is enabled, the character is suddenly reported as present:

~$ ./a.out
18446744073709551615
18446744073709551615
~$ valgrind -q ./a.out 
18446744073709551615
18446744073709551615
~$ valgrind --tool=massif -q ./a.out
0
18446744073709551615




EXPECTED RESULT


~$ ./a.out
18446744073709551615
18446744073709551615
~$ valgrind -q ./a.out 
18446744073709551615
18446744073709551615
~$ valgrind --tool=massif -q ./a.out
18446744073709551615
18446744073709551615


SOFTWARE/OS VERSIONS

OS: Oracle Linux 9
uname -a: Linux localhost.localdomain 5.15.0-101.103.2.1.el9uek.x86_64 #2 SMP
Tue May 2 01:10:45 PDT 2023 x86_64 x86_64 x86_64 GNU/Linux
g++: gcc version 11.3.1 20221121 (Red Hat 11.3.1-4.3.0.1) (GCC)

valgrind-3.19.0

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to