From: Diego Nieto Cid <[email protected]>
../../libdiskfs/dir-lookup.c: In function 'diskfs_S_dir_lookup':
../../libdiskfs/dir-lookup.c:312:21: warning: ignoring return value of
'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result]
312 | asprintf (&complete_path, "%s/%s",
dircred->po->path,
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
313 | translator_path);
| ~~~~~~~~~~~~~~~~
../../libdiskfs/dir-lookup.c:537:11: warning: ignoring return value of
'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result]
537 | asprintf (&newpi->po->path, "%s/%s", dircred->po->path,
relpath);
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
======================================================================
../../libdiskfs/init-startup.c: In function '_diskfs_init_completed':
../../libdiskfs/init-startup.c:233:3: warning: ignoring return value of
'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result]
233 | asprintf (&name,
| ^~~~~~~~~~~~~~~~
234 | "%s %s", program_invocation_short_name, diskfs_disk_name ?:
"-");
---
libdiskfs/dir-lookup.c | 21 +++++++++++++++++----
libdiskfs/init-startup.c | 6 ++++--
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index 32be3411..8c027795 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -23,6 +23,7 @@
#include <hurd/fshelp.h>
#include <hurd/fsys.h>
#include <hurd/paths.h>
+#include <assert-backtrace.h>
#include "priv.h"
#include "fs_S.h"
@@ -309,9 +310,18 @@ diskfs_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,
complete_path,
@@ -534,7 +544,10 @@ diskfs_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)
diff --git a/libdiskfs/init-startup.c b/libdiskfs/init-startup.c
index 0cc7f647..e7225c22 100644
--- a/libdiskfs/init-startup.c
+++ b/libdiskfs/init-startup.c
@@ -27,6 +27,7 @@
#include <hurd/fsys.h>
#include <hurd/paths.h>
#include <hurd/startup.h>
+#include <assert-backtrace.h>
#include "startup_S.h"
@@ -230,8 +231,9 @@ _diskfs_init_completed (void)
notify = ports_get_send_right (pi);
ports_port_deref (pi);
- asprintf (&name,
- "%s %s", program_invocation_short_name, diskfs_disk_name ?: "-");
+ err = asprintf (&name,
+ "%s %s", program_invocation_short_name, diskfs_disk_name ?:
"-");
+ assert_backtrace (err != -1);
err = startup_request_notification (init, notify,
MACH_MSG_TYPE_COPY_SEND, name);
mach_port_deallocate (mach_task_self (), notify);
--
2.51.0