Skip to content
Snippets Groups Projects
Commit 8bd5657a authored by Simon McVittie's avatar Simon McVittie
Browse files

inspect-library: Use glibc argz(3) to list hidden dependencies


This makes it easier for scan-build to understand that we are not doing
anything wrong here: parsing the command-line options twice should
result in the same number of items being put in hidden_deps[], but
scan-build can't know that.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent ecc78375
No related branches found
No related tags found
1 merge request!131Refactor inspect-library
Pipeline #4254 passed
......@@ -202,15 +202,17 @@ main (int argc,
ssize_t chars;
bool first;
bool deb_symbols = false;
size_t dependency_counter = 0;
int opt;
autofree char *hidden_deps = NULL;
size_t hidden_deps_len = 0;
const char *hidden_dep;
while ((opt = getopt_long (argc, argv, "", long_options, NULL)) != -1)
{
switch (opt)
{
case OPTION_HIDDEN_DEPENDENCY:
dependency_counter++;
argz_add_or_die (&hidden_deps, &hidden_deps_len, optarg);
break;
case OPTION_DEB_SYMBOLS:
......@@ -243,40 +245,19 @@ main (int argc,
usage (1);
}
const char *hidden_deps[dependency_counter + 1];
if (dependency_counter > 0)
{
/* Reset getopt */
optind = 1;
size_t i = 0;
while ((opt = getopt_long (argc, argv, "", long_options, NULL)) != -1)
{
switch (opt)
{
case OPTION_HIDDEN_DEPENDENCY:
hidden_deps[i] = optarg;
i++;
break;
default:
break;
}
}
}
soname = argv[optind];
printf ("{\n");
printf (" \"");
print_json_string_content (soname);
printf ("\": {");
for (size_t i = 0; i < dependency_counter; i++)
for (hidden_dep = argz_next (hidden_deps, hidden_deps_len, NULL);
hidden_dep != NULL;
hidden_dep = argz_next (hidden_deps, hidden_deps_len, hidden_dep))
{
/* We don't call "dlclose" on global hidden dependencies, otherwise ubsan
* will report an indirect memory leak */
if (dlopen (hidden_deps[i], RTLD_NOW|RTLD_GLOBAL) == NULL)
if (dlopen (hidden_dep, RTLD_NOW|RTLD_GLOBAL) == NULL)
{
fprintf (stderr, "Unable to find the dependency library: %s\n", dlerror ());
return 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment