Skip to content

Instantly share code, notes, and snippets.

@kulp
Created December 12, 2012 20:45
Show Gist options
  • Select an option

  • Save kulp/4271440 to your computer and use it in GitHub Desktop.

Select an option

Save kulp/4271440 to your computer and use it in GitHub Desktop.

Revisions

  1. kulp revised this gist Dec 13, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion check_range.c
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ unsigned check_range(const char *bad, const char *good, size_t len, size_t bound
    {
    if (len < 2) {
    if (len)
    return *(const char*)bad != *(const char*)good;
    return *bad != *good;
    return 0;
    } else if (memcmp(bad, good, len)) {
    size_t subbounds[2][2] = { { 0 } };
  2. kulp revised this gist Dec 12, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions check_range.c
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    unsigned check_range(const void *bad, const void *good, size_t len, size_t bounds[2])
    unsigned check_range(const char *bad, const char *good, size_t len, size_t bounds[2])
    {
    if (len < 2) {
    if (len)
    return *(const char*)bad != *(const char*)good;
    return 0;
    } else if (memcmp(bad, good, len)) {
    size_t subbounds[2][2] = { 0 };
    size_t subbounds[2][2] = { { 0 } };
    int leftbad = check_range(&bad[0 ], &good[0 ], len / 2, subbounds[0]);
    int rightbad = check_range(&bad[len / 2], &good[len / 2], len - len / 2, subbounds[1]);

  3. kulp revised this gist Dec 12, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion check_range.c
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ unsigned check_range(const void *bad, const void *good, size_t len, size_t bound
    return *(const char*)bad != *(const char*)good;
    return 0;
    } else if (memcmp(bad, good, len)) {
    size_t subbounds[2][2] = { 0 };
    size_t subbounds[2][2] = { 0 };
    int leftbad = check_range(&bad[0 ], &good[0 ], len / 2, subbounds[0]);
    int rightbad = check_range(&bad[len / 2], &good[len / 2], len - len / 2, subbounds[1]);

  4. kulp created this gist Dec 12, 2012.
    20 changes: 20 additions & 0 deletions check_range.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    unsigned check_range(const void *bad, const void *good, size_t len, size_t bounds[2])
    {
    if (len < 2) {
    if (len)
    return *(const char*)bad != *(const char*)good;
    return 0;
    } else if (memcmp(bad, good, len)) {
    size_t subbounds[2][2] = { 0 };
    int leftbad = check_range(&bad[0 ], &good[0 ], len / 2, subbounds[0]);
    int rightbad = check_range(&bad[len / 2], &good[len / 2], len - len / 2, subbounds[1]);

    // return leftmost and rightmost bad bounds
    bounds[0] = subbounds[ leftbad ? 0 : 1][0] + ( leftbad ? 0 : len - len / 2);
    bounds[1] = subbounds[rightbad ? 1 : 0][1] + (rightbad ? len - len / 2 : 0);

    return leftbad + rightbad;
    } else {
    return 0;
    }
    }