Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check return code of FindErrors in Decode #1

Merged
merged 1 commit into from
Jul 22, 2017

Conversation

chris-se
Copy link

In cases where the errors could not be corrected (but were detected) make sure Decode returns an error, so that the calling code knows that errors were detected, but could not be corrected.

You can test this by modifying the example. Add one more E so that it can't correct the error and check the return value of Decode:

char message[] = "Some very important message ought to be delivered";
const int msglen = sizeof(message);
const int ecclen = 8;
const int nErrors = 5;

char repaired[msglen];
char encoded[msglen + ecclen];


RS::ReedSolomon<msglen, ecclen> rs;

rs.Encode(message, encoded);

// Corrupting first 8 bytes of message (any 4 bytes can be repaired, no more)
for(uint i = 0; i < nErrors; i++) {
    encoded[i] = 'E';
}

int ok = rs.Decode(encoded, repaired);
if (ok != 0) {
    std::cout << "Couldn't repair the data" << std::endl;
    return;
}

std::cout << "Original:  " << message  << std::endl;
std::cout << "Corrupted: " << encoded  << std::endl;
std::cout << "Repaired:  " << repaired << std::endl;

std::cout << ((memcmp(message, repaired, msglen) == 0) ? "SUCCESS" : "FAILURE") << std::endl;

For nErrors == 5 this will fail the memcmp test but Decode will claim it was successful. (For other values of nErrors, for example 6, it might be the case that Decode will return an error, but for others it also won't.)

My patch fixes this example so that the caller can determine whether this was successful or not.

Otherwise many thanks for writing this!

In cases where the errors could not be corrected (but were detected)
make sure Decode returns an error, so that the calling code knows that
errors were detected, but could not be corrected.
@mersinvald
Copy link
Owner

Seems nice, thank you!

@mersinvald mersinvald merged commit b32a7f2 into mersinvald:master Jul 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants