From: Diego Nieto Cid <[email protected]>
../../libnetfs/dir-lookup.c: In function 'netfs_S_dir_lookup':
../../libnetfs/dir-lookup.c:304:19: warning: ignoring return value of
'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result]
304 | asprintf (&complete_path, "%s/%s",
dircred->po->path,
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305 | translator_path);
| ~~~~~~~~~~~~~~~~
../../libnetfs/dir-lookup.c:479:11: warning: ignoring return value of
'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result]
479 | asprintf (&newpi->po->path, "%s/%s", dircred->po->path,
relpath);
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
libnetfs/dir-lookup.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c
index 97732a4e..58caf015 100644
--- a/libnetfs/dir-lookup.c
+++ b/libnetfs/dir-lookup.c
@@ -301,8 +301,18 @@ netfs_S_dir_lookup (struct protid *dircred,
/* dircred is the root directory. */
complete_path = translator_path;
else
- asprintf (&complete_path, "%s/%s", dircred->po->path,
- translator_path);
+ {
+ /* Reuse the err variable. In case asprintf succeeds, it
is
+ * immediately ovewritten when the current block exits.
+ */
+ err = asprintf (&complete_path, "%s/%s",
dircred->po->path,
+ translator_path);
+ if (err == -1)
+ {
+ err = errno;
+ goto out;
+ }
+ }
notify_port = newpi->pi.bucket->notify_port;
err = fshelp_set_active_translator (notify_port,
@@ -476,7 +486,10 @@ netfs_S_dir_lookup (struct protid *dircred,
else
{
newpi->po->path = NULL;
- asprintf (&newpi->po->path, "%s/%s", dircred->po->path, relpath);
+ int err2 = asprintf (&newpi->po->path, "%s/%s", dircred->po->path,
relpath);
+ /* If asprintf fails set path to NULL so that the if below checks
errno. */
+ if (err2 == -1)
+ newpi->po->path = NULL;
}
if (! newpi->po->path)
--
2.51.0