https://bugs.kde.org/show_bug.cgi?id=444545
Bug ID: 444545
Summary: memchr behaves differently under valgrind
--tool=massif
Product: valgrind
Version: unspecified
Platform: Fedora RPMs
OS: Linux
Status: REPORTED
Severity: normal
Priority: NOR
Component: massif
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Created attachment 142965
--> https://bugs.kde.org/attachment.cgi?id=142965&action=edit
Test program showing issue
SUMMARY
Using the massif tool my program was malfunctioning. I reduced this to a simple
case where it appears that the behaviour of memchr is different when running
with massif to when running with memcheck, or running without valgrid
altogether
Using Valgrind 3.17
STEPS TO REPRODUCE
1. Compile program (attached) with 'gcc you.c'
2. Run 'valgrind --tool=massif ./a.out'
3. Run './a.out'
4. Observe output differs
OBSERVED RESULT
$ valgrind --tool=massif ./a.out
==9427== Massif, a heap profiler
==9427== Copyright (C) 2003-2017, and GNU GPL'd, by Nicholas Nethercote
==9427== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==9427== Command: ./a.out
==9427==
Found /DEF/GHI/JKL at 3
Found /GHI/JKL at 7
Found /JKL at 11
Found JKL at 12
Found KL at 13
Found L at 14
==9427==
EXPECTED RESULT
$ ./a.out
Found /DEF/GHI/JKL at 3
Found /GHI/JKL at 7
Found /JKL at 11
ALSO result with memcheck is correct
$ valgrind ./a.out
==9420== Memcheck, a memory error detector
==9420== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==9420== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==9420== Command: ./a.out
==9420==
Found /DEF/GHI/JKL at 3
Found /GHI/JKL at 7
Found /JKL at 11
==9420==
==9420== HEAP SUMMARY:
==9420== in use at exit: 0 bytes in 0 blocks
==9420== total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated
==9420==
==9420== All heap blocks were freed -- no leaks are possible
==9420==
==9420== For lists of detected and suppressed errors, rerun with: -s
==9420== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
SOFTWARE/OS VERSIONS
Fedora Linux 35 5.14.10-300.fc35.x86_64
ADDITIONAL INFORMATION
Program:
#include <stdio.h>
#include <string.h>
int main() {
const char* txt = "ABC/DEF/GHI/JKL";
int n = strlen(txt);
const char* ptr = txt;
while (ptr) {
const char* f = memchr(ptr, '/', txt + n - ptr);
if (f) {
printf("Found %s at %d\n", f, f - txt);
ptr = f + 1;
} else {
ptr = NULL;
}
}
return 0;
}
--
You are receiving this mail because:
You are watching all bug changes.