[CRIU] [PATCH 1/2] check return code of asprintf

Tycho Andersen tycho.andersen at canonical.com
Tue Apr 21 09:33:54 PDT 2015


On ubuntu (gcc 4.9.2), I get:

mount.c: In function ‘add_fsname_auto’:
mount.c:1414:3: error: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Werror=unused-result]
   asprintf(&fsauto_names, "%s,%s", old, names);
   ^
cc1: all warnings being treated as errors

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 mount.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mount.c b/mount.c
index 65f897b..1d41d82 100644
--- a/mount.c
+++ b/mount.c
@@ -1411,7 +1411,10 @@ bool add_fsname_auto(const char *names)
 		fsauto_names = xstrdup(names);
 	else {
 		fsauto_names = NULL;
-		asprintf(&fsauto_names, "%s,%s", old, names);
+		if (asprintf(&fsauto_names, "%s,%s", old, names) < 0) {
+			fsauto_names = old;
+			return false;
+		}
 	}
 
 	xfree(old);
-- 
2.1.4



More information about the CRIU mailing list