aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-11-08 23:40:01 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-11-08 23:40:01 -0500
commitb98b5b7d61a5285363c8cec4817f680ad96a12df (patch)
treeb5edc1f24d996fc1031212ea7c8f099e19807b60
parentb29c18ad9b449a02cd11bcbc27ef40f892089403 (diff)
downloadreloc-b98b5b7d61a5285363c8cec4817f680ad96a12df.tar.gz
Fix segfault while calculating base name
-rw-r--r--main.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/main.c b/main.c
index f590126..dadc455 100644
--- a/main.c
+++ b/main.c
@@ -116,7 +116,12 @@ void reloc_replace(RelocMatch *match, const char *rstr) {
int main(int argc, char *argv[]) {
- const char *program = strrchr(argv[0], DIRSEP) + 1;
+ char *program = argv[0];
+ char *program_relative = strrchr(program, DIRSEP);
+ if (program_relative) {
+ program = program_relative + 1;
+ }
+
if (argc < 5) {
printf("%s <str1> <str2> <input_file> <output_file>\n"
"\n"