diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-11-14 09:28:59 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-11-14 09:28:59 -0500 |
commit | 0e90fd78a1759af0af31e214aa4c4ba84ffd009d (patch) | |
tree | 3821aad56b2d42c6eee62f4363dc4a08fd3071f3 /main.c | |
parent | 0256732772c3fdf8a8adc77e54b848e1a2f92c75 (diff) | |
download | reloc-0e90fd78a1759af0af31e214aa4c4ba84ffd009d.tar.gz |
Incorporate error handler
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -43,14 +43,29 @@ int main(int argc, char *argv[]) { char *input_file = strdup(argv[3]); char *output_file = strdup(argv[4]); RelocData *info = reloc_read(input_file); + if (!info) { + reloc_perror(input_file); + exit(reloc_error); + } size_t records = 0; + size_t replacement_length = strlen(replacement); for (size_t i = 0; i < info->size; i++) { RelocMatch *match = NULL; if (!(match = reloc_match(&info->data[i], needle))) { + if (reloc_error) { + reloc_perror("reloc_match: "); + exit(reloc_error); + } // No match found continue; } + + if (replacement_length > match->length) { + fprintf(stderr, "Replacement string is too long ("SIZE_T_FMT " > " SIZE_T_FMT ")\n", replacement_length, match->length); + free(match); + continue; + } // Replace string reloc_replace(match, replacement); free(match); @@ -59,6 +74,10 @@ int main(int argc, char *argv[]) { // Write output file to disk reloc_write(info, output_file); + if (reloc_error) { + perror(output_file); + exit(reloc_error); + } // Report number of strings processed printf(SIZE_T_FMT"\n", records); |