Changeset 8478


Ignore:
Timestamp:
May 22, 2009, 5:35:51 AM (14 years ago)
Author:
charles
Message:

(trunk) dht seems to be crashing in bcmp() on the mac, so I suspect the homegrown implementation of memmem() is buggy... test this out by replacing memmem()'s implementation

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils-test.c

    r7854 r8478  
    226226}
    227227
     228static int
     229test_memmem( void )
     230{
     231    char const haystack[12] = "abcabcabcabc";
     232    char const needle[3] = "cab";
     233
     234    check( tr_memmem( haystack, sizeof haystack, haystack, sizeof haystack) == haystack )
     235    check( tr_memmem( haystack, sizeof haystack, needle, sizeof needle) == haystack + 2 )
     236    check( tr_memmem( needle, sizeof needle, haystack, sizeof haystack) == NULL )
     237    check( tr_memmem( haystack, sizeof haystack, "", 0) == haystack )
     238    check( tr_memmem( haystack, sizeof haystack, NULL, 0) == haystack )
     239    check( tr_memmem( haystack, 0, "", 0) == haystack )
     240
     241    return 0;
     242}
     243
    228244int
    229245main( void )
     
    254270    if( ( i = test_numbers( ) ) )
    255271        return i;
     272    if( ( i = test_memmem( ) ) )
     273        return i;
    256274
    257275    /* test that tr_cryptoRandInt() stays in-bounds */
  • trunk/libtransmission/utils.c

    r8450 r8478  
    696696#else
    697697    size_t i;
    698     for( i=0; i<haystacklen-needlelen; ++i )
     698    if( !needlelen )
     699        return haystack;
     700    if( needlelen > haystacklen || !haystack || !needle )
     701        return NULL;
     702    for( i=0; i<=haystacklen-needlelen; ++i )
    699703        if( !memcmp( haystack+i, needle, needlelen ) )
    700704            return haystack+i;
  • trunk/third-party/dht/dht.c

    r8462 r8478  
    21112111    size_t i;
    21122112
    2113     for(i = 0; i < haystacklen - needlelen; i++) {
     2113    if(needlelen > haystacklen)
     2114        return NULL;
     2115
     2116    for(i = 0; i <= haystacklen - needlelen; i++) {
    21142117        if(memcmp(h + i, n, needlelen) == 0)
    21152118            return (void*)(h + i);
Note: See TracChangeset for help on using the changeset viewer.