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

Attachment: smime.p7s
Description: Signature cryptographique S/MIME

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to