|
From: Francis G. <fra...@gm...> - 2012-08-12 17:17:21
|
Le 2012-08-12 18:56, Philippe Waroquiers a écrit :
> On Sun, 2012-08-12 at 18:10 +0200, Francis Giraldeau wrote:
>> Of course you are right! Thought, I just tested without updating dst and
>> the problem is raised anyway. The error is not caused in the printf(),
>> but in the stpncpy().
> String functions might be optimised very specially by the compiler
> and then might not be redirected by Valgrind.
> There has been some changes in the area of sse instructions
> and some replacement of string functions in 3.8.0.
> => would be good to try with the 3.8.0.
I just tested and it produces the same error with valgrind 3.8.0.
> You can also (with or without the previous builtin trial)
> examine the output of Valgrind (-v) to see if the stpncpy
> function is properly redirected to the valgrind one.
>
>>From what I can see, there is no replacement for stpncpy.
> So, the optimised code is then not replaced.
I confirm this too. I did a trivial implementation of stpcpy/stpncpy
with strcpy and it do not raise the issue. Maybe they can be a basis for
an additional REDIR?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static char *_stpcpy(char *dest, const char *src) {
strcpy(dest, src);
size_t len = strlen(src);
return dest + len;
}
static char *_stpncpy(char *dest, const char *src, size_t len) {
strcpy(dest, src);
return dest + len;
}
int main(int argc, char **argv) {
char *dst = (char *) calloc(4, 1);
char *src = (char *) calloc(4, 1);
src[0] = 'a';
src[1] = 'b';
src[2] = 'c';
src[3] = '\0';
_stpncpy(dst, src, 3);
printf("%s %s\n", src, dst);
free(src);
free(dst);
}
At least in this particular case it's a false positive and thus, I can
ignore safely the warning. Thanks a lot for your feedback!
Cheers,
Francis
|