summaryrefslogtreecommitdiffstats
path: root/src/binary_location.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-27 17:57:54 +0100
committerDavid Robillard <d@drobilla.net>2020-11-27 21:42:51 +0100
commit0c3ad17808e19c7c873ca3f85feca87f5a8b9cca (patch)
tree3146d56b8fb64db90e93879e057bd54c4f9ad8a0 /src/binary_location.h
parentd77dc2fca66d1a333f642d53e209ef4f0b6241c3 (diff)
downloadpatchage-0c3ad17808e19c7c873ca3f85feca87f5a8b9cca.tar.gz
patchage-0c3ad17808e19c7c873ca3f85feca87f5a8b9cca.tar.bz2
patchage-0c3ad17808e19c7c873ca3f85feca87f5a8b9cca.zip
Avoid C casts
Diffstat (limited to 'src/binary_location.h')
-rw-r--r--src/binary_location.h22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/binary_location.h b/src/binary_location.h
index 3705d94..f949649 100644
--- a/src/binary_location.h
+++ b/src/binary_location.h
@@ -1,5 +1,5 @@
/* This file is part of Patchage.
- * Copyright 2008-2014 David Robillard <http://drobilla.net>
+ * Copyright 2008-2020 David Robillard <d@drobilla.net>
*
* Patchage is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
@@ -29,15 +29,19 @@
inline std::string
binary_location()
{
- Dl_info dli;
- std::string loc;
- const int ret = dladdr((void*)&binary_location, &dli);
- if (ret) {
- if (char* const bin_loc = realpath(dli.dli_fname, nullptr)) {
- loc = bin_loc;
- free(bin_loc);
- }
+ Dl_info dli = {};
+ const int ret = dladdr(reinterpret_cast<void*>(&binary_location), &dli);
+ if (!ret) {
+ return "";
}
+
+ char* const bin_loc = realpath(dli.dli_fname, nullptr);
+ if (!bin_loc) {
+ return "";
+ }
+
+ std::string loc{bin_loc};
+ free(bin_loc);
return loc;
}