[PATCH] [tsan] Fix strcmp/strncmp interceptor return value

Alexey Samsonov samsonov at google.com
Tue Jul 16 05:53:44 PDT 2013


On Tue, Jul 16, 2013 at 1:31 PM, Kostya Serebryany <kcc at google.com> wrote:

> Alexey, could you please take a look?
>
> The proper fix, imho, is to move the appropriate interceptors
> from asan/asan_interceptors.cc to
> sanitizer_common/sanitizer_common_interceptors.inc and delete the
> incorrect copies from
> tsan/rtl/tsan_interceptors.cc
>

Did this in r186408.


>
>
>
> On Thu, Jul 11, 2013 at 9:19 PM, Matthew Dempsky <matthew at dempsky.org>wrote:
>
>> C99 says memcmp, strcmp, and strncmp return the difference of
>> character values interpreted as unsigned char values.  tsan's memcmp
>> interceptor already does this correctly, but strcmp and strncmp do
>> not.
>>
>> Untested patch below.
>>
>> Index: tsan_interceptors.cc
>> ===================================================================
>> --- tsan_interceptors.cc        (revision 186094)
>> +++ tsan_interceptors.cc        (working copy)
>> @@ -599,7 +599,7 @@
>>    }
>>    MemoryAccessRange(thr, pc, (uptr)s1, len + 1, false);
>>    MemoryAccessRange(thr, pc, (uptr)s2, len + 1, false);
>> -  return s1[len] - s2[len];
>> +  return (unsigned char)s1[len] - (unsigned char)s2[len];
>>  }
>>
>>  TSAN_INTERCEPTOR(int, strncmp, const char *s1, const char *s2, uptr n) {
>> @@ -611,7 +611,7 @@
>>    }
>>    MemoryAccessRange(thr, pc, (uptr)s1, len < n ? len + 1 : n, false);
>>    MemoryAccessRange(thr, pc, (uptr)s2, len < n ? len + 1 : n, false);
>> -  return len == n ? 0 : s1[len] - s2[len];
>> +  return len == n ? 0 : (unsigned char)s1[len] - (unsigned char)s2[len];
>>  }
>>
>>  TSAN_INTERCEPTOR(void*, memchr, void *s, int c, uptr n) {
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>


-- 
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130716/3a308635/attachment.html>


More information about the llvm-commits mailing list