Fix bug in Named CRC lookup
This commit is contained in:
parent
8f19470db3
commit
ea00a0756e
14
main.c
14
main.c
@ -69,6 +69,7 @@ struct command_line_options {
|
|||||||
static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
||||||
{
|
{
|
||||||
struct command_line_options *args = (struct command_line_options *)state->input;
|
struct command_line_options *args = (struct command_line_options *)state->input;
|
||||||
|
const struct named_crc *looked_up_crc;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
@ -91,7 +92,11 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
|||||||
/* Polyniomial */
|
/* Polyniomial */
|
||||||
args->crc.polynomial = strtoull(arg, &endptr, 0);
|
args->crc.polynomial = strtoull(arg, &endptr, 0);
|
||||||
if (endptr == arg) {
|
if (endptr == arg) {
|
||||||
argp_error(state, "Error parsing polynomial: %s\n", arg);
|
if ((looked_up_crc = lookup_named_crc(arg))) {
|
||||||
|
memcpy(&args->crc, &looked_up_crc->settings, sizeof(struct crc_settings));
|
||||||
|
} else {
|
||||||
|
argp_error(state, "Error parsing polynomial: %s\n", arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
@ -246,6 +251,13 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Build the CRC */
|
/* Build the CRC */
|
||||||
crc_init(&crc, &cmd_opts.crc);
|
crc_init(&crc, &cmd_opts.crc);
|
||||||
|
|
||||||
|
/* Perform the check test */
|
||||||
|
crc_push_bytes(&crc, "123456789", 9u);
|
||||||
|
crc_finish_calc(&crc);
|
||||||
|
printf("CRC Check value: 0x%08x\n", crc_get_value(&crc));
|
||||||
|
|
||||||
|
crc_destroy(&crc);
|
||||||
free_cmds:
|
free_cmds:
|
||||||
|
|
||||||
free_cmd_args(&cmd_opts);
|
free_cmd_args(&cmd_opts);
|
||||||
|
@ -97,7 +97,7 @@ const struct named_crc *lookup_named_crc(const char *name)
|
|||||||
const struct named_crc *found = NULL;
|
const struct named_crc *found = NULL;
|
||||||
|
|
||||||
for (iter = predefined_crc_table; iter->name; iter++) {
|
for (iter = predefined_crc_table; iter->name; iter++) {
|
||||||
if (strcmp(iter->name, name)) {
|
if (!strcmp(iter->name, name)) {
|
||||||
found = iter;
|
found = iter;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user