[patchset] introduce an -O3 autobuild target - and fix a lot of errors

Michael Adam obnox at samba.org
Mon Apr 11 14:33:53 UTC 2016


Updated patchset attached!

Cheers - Michael

On 2016-04-11 at 11:12 +0200, Michael Adam wrote:
> After feed-back by Volker, will provide an updated
> patchset soon which will only use EINTR checks in
> sys_read/write_v functions and hand-written loops,
> i.e. not also check for EAGAIN or EWOULDBLOCK,
> in order to avoid the danger of endless loops.
> 
> Cheers - Michael
> 
> On 2016-04-11 at 10:35 +0200, Michael Adam wrote:
> > Hi,
> > 
> > Attached find a patchset that implements an autobuild target
> > 'samba-o3', that builds with -O3 and runs some tests against
> > the result (make quicktest...).
> > 
> > In order to enable this target by default, I had to fix quite
> > a lot of -O3 errors, so that the build would pass on our
> > autobuild server. Now it passes on ubuntu 14.04 and fedora 23
> > at least.
> > 
> > Andrew: I have kept at a separate build target because I
> > also wanted to make sure to run at least a subset of the
> > testsuite against it. Hence I did not add it to the static
> > target.
> > 
> > Review / comments welcome!
> > 
> > Cheers - Michael
> 


-------------- next part --------------
From 9959e59d4cf16dc4a9326f70187c403086b2e15f Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 22 Mar 2016 18:14:17 +0100
Subject: [PATCH 01/41] autobuild: add a target samba-o3 that is built with -O3

Only run quicktest against the ad_dc env.
This currently just takes some 6 odd minutes.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 script/autobuild.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/script/autobuild.py b/script/autobuild.py
index 4cad920..6b7eca2 100755
--- a/script/autobuild.py
+++ b/script/autobuild.py
@@ -24,6 +24,7 @@ builddirs = {
     "ctdb"    : "ctdb",
     "samba"  : ".",
     "samba-xc" : ".",
+    "samba-o3" : ".",
     "samba-ctdb" : ".",
     "samba-libs"  : ".",
     "samba-static"  : ".",
@@ -79,6 +80,14 @@ tasks = {
                     " --cross-answers=./bin-xe/cross-answers.txt --with-selftest-prefix=./bin-xa/ab" + samba_configure_params, "text/plain"),
                    ("compare-results", "script/compare_cc_results.py ./bin/c4che/default.cache.py ./bin-xe/c4che/default.cache.py ./bin-xa/c4che/default.cache.py", "text/plain")],
 
+    # test build with -O3 -- catches extra warnings and bugs
+    "samba-o3" : [ ("random-sleep", "../script/random-sleep.sh 60 600", "text/plain"),
+                   ("configure", "ADDITIONAL_CFLAGS='-O3' ./configure.developer --with-selftest-prefix=./bin/ab" + samba_configure_params, "text/plain"),
+                   ("make", "make -j", "text/plain"),
+                   ("test", "make quicktest FAIL_IMMEDIATELY=1 TESTS='\(ad_dc\)'", "text/plain"),
+                   ("install", "make install", "text/plain"),
+                   ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
+                   ("clean", "make clean", "text/plain") ],
 
     "samba-ctdb" : [ ("random-sleep", "script/random-sleep.sh 60 600", "text/plain"),
 
-- 
2.5.5


From ef213d930c7ee357ee5081d97830463c2b9d43c5 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 23 Mar 2016 01:41:17 +0100
Subject: [PATCH 02/41] tevent:threads: fix -O3 error unused result of write

some compilers don't tolerate void-casting for warn_unused_result

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/tevent/tevent_threads.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/tevent/tevent_threads.c b/lib/tevent/tevent_threads.c
index 8d44e4f..15882e4 100644
--- a/lib/tevent/tevent_threads.c
+++ b/lib/tevent/tevent_threads.c
@@ -310,6 +310,7 @@ void tevent_thread_proxy_schedule(struct tevent_thread_proxy *tp,
 	struct tevent_immediate_list *im_entry;
 	int ret;
 	char c;
+	ssize_t written;
 
 	ret = pthread_mutex_lock(&tp->mutex);
 	if (ret != 0) {
@@ -341,7 +342,9 @@ void tevent_thread_proxy_schedule(struct tevent_thread_proxy *tp,
 
 	/* And notify the dest_ev_ctx to wake up. */
 	c = '\0';
-	(void)write(tp->write_fd, &c, 1);
+	do {
+		written = write(tp->write_fd, &c, 1);
+	} while (written == -1 && errno == EINTR);
 
   end:
 
-- 
2.5.5


From 2a64be00f2d90323e96279053399666500723bbd Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 23 Mar 2016 01:41:29 +0100
Subject: [PATCH 03/41] tevent:signal: fix -O3 error unused result of write

some compilers don't tolerate void-casting for warn_unused_result

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/tevent/tevent_signal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/tevent/tevent_signal.c b/lib/tevent/tevent_signal.c
index 9bc11ed..8a0caae 100644
--- a/lib/tevent/tevent_signal.c
+++ b/lib/tevent/tevent_signal.c
@@ -106,9 +106,13 @@ static void tevent_common_signal_handler(int signum)
 	/* Write to each unique event context. */
 	for (sl = sig_state->sig_handlers[signum]; sl; sl = sl->next) {
 		if (sl->se->event_ctx && sl->se->event_ctx != ev) {
+			ssize_t ret;
+
 			ev = sl->se->event_ctx;
 			/* doesn't matter if this pipe overflows */
-			(void) write(ev->pipe_fds[1], &c, 1);
+			do {
+				ret = write(ev->pipe_fds[1], &c, 1);
+			} while (ret == -1 && errno == EINTR);
 		}
 	}
 
-- 
2.5.5


From b35c206e65ee257716ed10c1bcecb55d80fbbbb4 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 23 Mar 2016 02:23:35 +0100
Subject: [PATCH 04/41] tevent:signal: fix -O3 error unused result of read

some compilers don't tolerate void-casting for warn_unused_result

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/tevent/tevent_signal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/tevent/tevent_signal.c b/lib/tevent/tevent_signal.c
index 8a0caae..635a7a1 100644
--- a/lib/tevent/tevent_signal.c
+++ b/lib/tevent/tevent_signal.c
@@ -238,9 +238,13 @@ static int tevent_signal_destructor(struct tevent_signal *se)
 static void signal_pipe_handler(struct tevent_context *ev, struct tevent_fd *fde, 
 				uint16_t flags, void *_private)
 {
+	ssize_t ret;
+
 	char c[16];
 	/* its non-blocking, doesn't matter if we read too much */
-	(void) read(fde->fd, c, sizeof(c));
+	do {
+		ret = read(fde->fd, c, sizeof(c));
+	} while (ret == -1 && errno == EINTR);
 }
 
 /*
-- 
2.5.5


From 1d395f715a40e245cfe6eb6ccb53b391649b3546 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 18:40:37 +0200
Subject: [PATCH 05/41] tevent:testsuite: fix O3 errors unused result for read

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/tevent/testsuite.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/tevent/testsuite.c b/lib/tevent/testsuite.c
index bcd27fd..013bc32 100644
--- a/lib/tevent/testsuite.c
+++ b/lib/tevent/testsuite.c
@@ -38,6 +38,15 @@
 
 static int fde_count;
 
+static void do_read(int fd, void *buf, size_t count)
+{
+	ssize_t ret;
+
+	do {
+		ret = read(fd, buf, count);
+	} while (ret == -1 && errno == EINTR);
+}
+
 static void fde_handler_read(struct tevent_context *ev_ctx, struct tevent_fd *f,
 			uint16_t flags, void *private_data)
 {
@@ -48,7 +57,7 @@ static void fde_handler_read(struct tevent_context *ev_ctx, struct tevent_fd *f,
 #endif
 	kill(getpid(), SIGALRM);
 
-	read(fd[0], &c, 1);
+	do_read(fd[0], &c, 1);
 	fde_count++;
 }
 
@@ -72,7 +81,7 @@ static void fde_handler_read_1(struct tevent_context *ev_ctx, struct tevent_fd *
 #endif
 	kill(getpid(), SIGALRM);
 
-	read(fd[1], &c, 1);
+	do_read(fd[1], &c, 1);
 	fde_count++;
 }
 
-- 
2.5.5


From 4fdfaeabac0a9eecf47665ef8677f951434398aa Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 18:51:13 +0200
Subject: [PATCH 06/41] tevent:testsuite: fix O3 errors unused result of write

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/tevent/testsuite.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/lib/tevent/testsuite.c b/lib/tevent/testsuite.c
index 013bc32..b37c7b1 100644
--- a/lib/tevent/testsuite.c
+++ b/lib/tevent/testsuite.c
@@ -61,12 +61,22 @@ static void fde_handler_read(struct tevent_context *ev_ctx, struct tevent_fd *f,
 	fde_count++;
 }
 
+static void do_write(int fd, void *buf, size_t count)
+{
+	ssize_t ret;
+
+	do {
+		ret = write(fd, buf, count);
+	} while (ret == -1 && errno == EINTR);
+}
+
 static void fde_handler_write(struct tevent_context *ev_ctx, struct tevent_fd *f,
 			uint16_t flags, void *private_data)
 {
 	int *fd = (int *)private_data;
 	char c = 0;
-	write(fd[1], &c, 1);
+
+	do_write(fd[1], &c, 1);
 }
 
 
@@ -91,7 +101,7 @@ static void fde_handler_write_1(struct tevent_context *ev_ctx, struct tevent_fd
 {
 	int *fd = (int *)private_data;
 	char c = 0;
-	write(fd[0], &c, 1);
+	do_write(fd[0], &c, 1);
 }
 
 static void finished_handler(struct tevent_context *ev_ctx, struct tevent_timer *te,
@@ -290,7 +300,7 @@ static void test_event_fd1_fde_handler(struct tevent_context *ev_ctx,
 		/*
 		 * we write to the other socket...
 		 */
-		write(state->sock[1], &c, 1);
+		do_write(state->sock[1], &c, 1);
 		TEVENT_FD_NOT_WRITEABLE(fde);
 		TEVENT_FD_READABLE(fde);
 		return;
@@ -659,9 +669,9 @@ static bool test_event_fd2(struct torture_context *tctx,
 	tevent_fd_set_auto_close(state.sock0.fde);
 	tevent_fd_set_auto_close(state.sock1.fde);
 
-	write(state.sock0.fd, &c, 1);
+	do_write(state.sock0.fd, &c, 1);
 	state.sock0.num_written++;
-	write(state.sock1.fd, &c, 1);
+	do_write(state.sock1.fd, &c, 1);
 	state.sock1.num_written++;
 
 	while (!state.finished) {
@@ -801,7 +811,7 @@ static bool test_event_context_threaded(struct torture_context *test,
 
 	poll(NULL, 0, 100);
 
-	write(fds[1], &c, 1);
+	do_write(fds[1], &c, 1);
 
 	poll(NULL, 0, 100);
 
@@ -809,7 +819,7 @@ static bool test_event_context_threaded(struct torture_context *test,
 	do_shutdown = true;
 	test_event_threaded_unlock();
 
-	write(fds[1], &c, 1);
+	do_write(fds[1], &c, 1);
 
 	ret = pthread_join(poll_thread, NULL);
 	torture_assert(test, ret == 0, "pthread_join failed");
-- 
2.5.5


From e0029facad9feecf71be99ce700ab5a8357cd079 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 23 Mar 2016 02:36:04 +0100
Subject: [PATCH 07/41] tdb:torture: fix -O3 error unused result code of read

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/tdb/tools/tdbtorture.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/tdb/tools/tdbtorture.c b/lib/tdb/tools/tdbtorture.c
index e4b8f69..331a459 100644
--- a/lib/tdb/tools/tdbtorture.c
+++ b/lib/tdb/tools/tdbtorture.c
@@ -427,8 +427,12 @@ int main(int argc, char * const *argv)
 			    || WTERMSIG(status) == SIGUSR1) {
 				/* SIGUSR2 means they wrote to pipe. */
 				if (WTERMSIG(status) == SIGUSR2) {
-					read(pfds[0], &done[j],
-					     sizeof(done[j]));
+					ssize_t ret;
+
+					do {
+						ret = read(pfds[0], &done[j],
+							   sizeof(done[j]));
+					} while (ret == -1 && errno == EINTR);
 				}
 				pids[j] = fork();
 				if (pids[j] == 0)
-- 
2.5.5


From 246012ee05e7de5fa94ce75596645cbbe4a9f9d0 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 23 Mar 2016 02:47:13 +0100
Subject: [PATCH 08/41] tdb:torture: fix -O3 error unused result of write

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/tdb/tools/tdbtorture.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/tdb/tools/tdbtorture.c b/lib/tdb/tools/tdbtorture.c
index 331a459..3640dc7 100644
--- a/lib/tdb/tools/tdbtorture.c
+++ b/lib/tdb/tools/tdbtorture.c
@@ -223,8 +223,12 @@ static void usage(void)
 
 static void send_count_and_suicide(int sig)
 {
+	ssize_t ret;
+
 	/* This ensures our successor can continue where we left off. */
-	write(count_pipe, &loopnum, sizeof(loopnum));
+	do {
+		ret = write(count_pipe, &loopnum, sizeof(loopnum));
+	} while (ret == -1 && errno == EINTR);
 	/* This gives a unique signature. */
 	kill(getpid(), SIGUSR2);
 }
-- 
2.5.5


From eec47968e425f76b5d31c1db9c34eb69e52c8ad5 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 22 Mar 2016 23:01:10 +0100
Subject: [PATCH 09/41] debug: fix -O3 warning - unused return code of write()

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/util/debug.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 4bb54d7..95b3d95 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -139,8 +139,12 @@ static int debug_level_to_priority(int level)
 static void debug_file_log(int msg_level,
 			   const char *msg, const char *msg_no_nl)
 {
+	ssize_t ret;
+
 	check_log_size();
-	write(state.fd, msg, strlen(msg));
+	do {
+		ret = write(state.fd, msg, strlen(msg));
+	} while (ret == -1 && errno == EINTR);
 }
 
 #ifdef WITH_SYSLOG
@@ -1114,7 +1118,10 @@ static void Debug1(const char *msg)
 	case DEBUG_DEFAULT_STDOUT:
 	case DEBUG_DEFAULT_STDERR:
 		if (state.fd > 0) {
-			write(state.fd, msg, strlen(msg));
+			ssize_t ret;
+			do {
+				ret = write(state.fd, msg, strlen(msg));
+			} while (ret == -1 && errno == EINTR);
 		}
 		break;
 	case DEBUG_FILE:
-- 
2.5.5


From 1689e0328c109219e0f952879a029ccd4034ccb7 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Fri, 25 Mar 2016 01:28:27 +0100
Subject: [PATCH 10/41] lib: add sys_read_v - void variant of sys_read

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/util/sys_rw.c | 16 ++++++++++++++++
 lib/util/sys_rw.h |  1 +
 2 files changed, 17 insertions(+)

diff --git a/lib/util/sys_rw.c b/lib/util/sys_rw.c
index f625066..3962d49 100644
--- a/lib/util/sys_rw.c
+++ b/lib/util/sys_rw.c
@@ -40,6 +40,22 @@ ssize_t sys_read(int fd, void *buf, size_t count)
 	return ret;
 }
 
+/**
+ * read wrapper, void variant:
+ * This is intended to be used as a void variant of
+ * read in situations where the caller wants to ignore
+ * the result. Hence not checking for EAGAIN|EWOULDBLOCK.
+ */
+void sys_read_v(int fd, void *buf, size_t count)
+{
+	ssize_t ret;
+
+	do {
+		ret = read(fd, buf, count);
+	} while (ret == -1 && errno == EINTR);
+}
+
+
 /*******************************************************************
 A write wrapper that will deal with EINTR/EWOULDBLOCK.
 ********************************************************************/
diff --git a/lib/util/sys_rw.h b/lib/util/sys_rw.h
index ee1584e..6b708a8 100644
--- a/lib/util/sys_rw.h
+++ b/lib/util/sys_rw.h
@@ -28,6 +28,7 @@
 struct iovec;
 
 ssize_t sys_read(int fd, void *buf, size_t count);
+void sys_read_v(int fd, void *buf, size_t count);
 ssize_t sys_write(int fd, const void *buf, size_t count);
 ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt);
 ssize_t sys_pread(int fd, void *buf, size_t count, off_t off);
-- 
2.5.5


From 11229669908c3e3dab716040dafe3a5355d2d8d2 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Fri, 25 Mar 2016 01:28:56 +0100
Subject: [PATCH 11/41] lib: add sys_write_v - void variant of sys_write

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/util/sys_rw.c | 17 +++++++++++++++++
 lib/util/sys_rw.h |  1 +
 2 files changed, 18 insertions(+)

diff --git a/lib/util/sys_rw.c b/lib/util/sys_rw.c
index 3962d49..9a6cdca 100644
--- a/lib/util/sys_rw.c
+++ b/lib/util/sys_rw.c
@@ -72,6 +72,23 @@ ssize_t sys_write(int fd, const void *buf, size_t count)
 	return ret;
 }
 
+/**
+ * write wrapper to deal with EINTR and friends.
+ * void-variant that ignores the number of bytes written.
+ * This is intended to be used as a void variant of
+ * write in situations where the caller wants to ignore
+ * the result. Hence not checking for EAGAIN|EWOULDBLOCK.
+ */
+void sys_write_v(int fd, const void *buf, size_t count)
+{
+	ssize_t ret;
+
+	do {
+		ret = write(fd, buf, count);
+	} while (ret == -1 && errno == EINTR);
+}
+
+
 /*******************************************************************
 A writev wrapper that will deal with EINTR.
 ********************************************************************/
diff --git a/lib/util/sys_rw.h b/lib/util/sys_rw.h
index 6b708a8..ab456d8 100644
--- a/lib/util/sys_rw.h
+++ b/lib/util/sys_rw.h
@@ -30,6 +30,7 @@ struct iovec;
 ssize_t sys_read(int fd, void *buf, size_t count);
 void sys_read_v(int fd, void *buf, size_t count);
 ssize_t sys_write(int fd, const void *buf, size_t count);
+void sys_write_v(int fd, const void *buf, size_t count);
 ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt);
 ssize_t sys_pread(int fd, void *buf, size_t count, off_t off);
 ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off);
-- 
2.5.5


From 864543e1800360dfab5632b4f35e1272c3b5ee12 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Fri, 25 Mar 2016 01:29:40 +0100
Subject: [PATCH 12/41] s4:libcli:resolve: fix O3 error unused result of write

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/libcli/resolve/dns_ex.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/source4/libcli/resolve/dns_ex.c b/source4/libcli/resolve/dns_ex.c
index 08b6932..6174b61 100644
--- a/source4/libcli/resolve/dns_ex.c
+++ b/source4/libcli/resolve/dns_ex.c
@@ -41,6 +41,7 @@
 #include "lib/util/util_net.h"
 #include "lib/addns/dnsquery.h"
 #include "lib/addns/dns.h"
+#include "lib/util/sys_rw.h"
 #include <arpa/nameser.h>
 #include <resolv.h>
 
@@ -370,7 +371,7 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd)
 
 	if (addrs) {
 		DEBUG(11, ("Addrs = %s\n", addrs));
-		write(fd, addrs, talloc_get_size(addrs));
+		sys_write_v(fd, addrs, talloc_get_size(addrs));
 	}
 
 done:
@@ -436,7 +437,7 @@ static void run_child_getaddrinfo(struct dns_ex_state *state, int fd)
 	}
 
 	if (addrs) {
-		write(fd, addrs, talloc_get_size(addrs));
+		sys_write_v(fd, addrs, talloc_get_size(addrs));
 	}
 done:
 	if (res_list) {
-- 
2.5.5


From ca6821c82e490db5d0dff1405d6015f377e0022f Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Fri, 25 Mar 2016 02:04:58 +0100
Subject: [PATCH 13/41] s4:registry:patchfile: fix O3 error unused result of
 write

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/lib/registry/patchfile_preg.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c
index 8017b58..19ebb6a 100644
--- a/source4/lib/registry/patchfile_preg.c
+++ b/source4/lib/registry/patchfile_preg.c
@@ -23,6 +23,7 @@
 #include "lib/registry/registry.h"
 #include "system/filesys.h"
 #include "librpc/gen_ndr/winreg.h"
+#include "lib/util/sys_rw.h"
 
 struct preg_data {
 	int fd;
@@ -71,12 +72,12 @@ static WERROR reg_preg_diff_set_value(void *_data, const char *key_name,
 	preg_write_utf16(data->fd, value_name);
 	preg_write_utf16(data->fd, ";");
 	SIVAL(&buf, 0, value_type);
-	write(data->fd, &buf, sizeof(uint32_t));
+	sys_write_v(data->fd, &buf, sizeof(uint32_t));
 	preg_write_utf16(data->fd, ";");
 	SIVAL(&buf, 0, value_data.length);
-	write(data->fd, &buf, sizeof(uint32_t));
+	sys_write_v(data->fd, &buf, sizeof(uint32_t));
 	preg_write_utf16(data->fd, ";");
-	write(data->fd, value_data.data, value_data.length);
+	sys_write_v(data->fd, value_data.data, value_data.length);
 	preg_write_utf16(data->fd, "]");
 	
 	return WERR_OK;
@@ -189,7 +190,7 @@ _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename,
 
 	memcpy(preg_header.hdr, "PReg", sizeof(preg_header.hdr));
 	SIVAL(&preg_header.version, 0, 1);
-	write(data->fd, (uint8_t *)&preg_header, sizeof(preg_header));
+	sys_write_v(data->fd, (uint8_t *)&preg_header, sizeof(preg_header));
 
 	data->ctx = ctx;
 
-- 
2.5.5


From a8aa9543bef1e43aa3a1339d28e529a9b479ef5a Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Sat, 26 Mar 2016 01:53:00 +0100
Subject: [PATCH 14/41] s4:ntvfs: fix O3 error unused result of asprintf

in svfs_map_fileinfo

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/ntvfs/simple/vfs_simple.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/source4/ntvfs/simple/vfs_simple.c b/source4/ntvfs/simple/vfs_simple.c
index 38ecdfe..abd76d2 100644
--- a/source4/ntvfs/simple/vfs_simple.c
+++ b/source4/ntvfs/simple/vfs_simple.c
@@ -206,7 +206,7 @@ static NTSTATUS svfs_map_fileinfo(struct ntvfs_module_context *ntvfs,
 {
 	struct svfs_dir *dir = NULL;
 	char *pattern = NULL;
-	int i;
+	int i, ret;
 	const char *s, *short_name;
 
 	s = strrchr(unix_path, '/');
@@ -216,8 +216,11 @@ static NTSTATUS svfs_map_fileinfo(struct ntvfs_module_context *ntvfs,
 		short_name = "";
 	}
 
-	asprintf(&pattern, "%s:*", unix_path);
-	
+	ret = asprintf(&pattern, "%s:*", unix_path);
+	if (ret == -1) {
+		return NT_STATUS_NO_MEMORY;
+	}
+
 	if (pattern) {
 		dir = svfs_list_unix(req, req, pattern);
 	}
-- 
2.5.5


From 26885663dd113e9ce26005339941fe5d49122842 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Sat, 26 Mar 2016 02:08:41 +0100
Subject: [PATCH 15/41] s4:ntvfs: fix O3 error unused result of asprintf in
 svfs_file_utime

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/ntvfs/simple/svfs_util.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/source4/ntvfs/simple/svfs_util.c b/source4/ntvfs/simple/svfs_util.c
index c4e0156..171813b 100644
--- a/source4/ntvfs/simple/svfs_util.c
+++ b/source4/ntvfs/simple/svfs_util.c
@@ -158,7 +158,12 @@ int svfs_file_utime(int fd, struct utimbuf *times)
 	char *fd_path = NULL;
 	int ret;
 
-	asprintf(&fd_path, "/proc/self/%d", fd);
+	ret = asprintf(&fd_path, "/proc/self/%d", fd);
+	if (ret == -1) {
+		errno = ENOMEM;
+		return -1;
+	}
+
 	if (!fd_path) {
 		errno = ENOMEM;
 		return -1;
-- 
2.5.5


From a62a63063f0f1ac7b28262e3a485e02e0319f519 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Sat, 26 Mar 2016 02:24:08 +0100
Subject: [PATCH 16/41] s4:ntvfs: fix O3 error unused result of asprintf in
 cifspsx_map_fileinfo

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c b/source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c
index d384dbb..9c1e6f6 100644
--- a/source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c
+++ b/source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c
@@ -209,7 +209,7 @@ static NTSTATUS cifspsx_map_fileinfo(struct ntvfs_module_context *ntvfs,
 {
 	struct cifspsx_dir *dir = NULL;
 	char *pattern = NULL;
-	int i;
+	int i, ret;
 	const char *s, *short_name;
 
 	s = strrchr(unix_path, '/');
@@ -219,8 +219,11 @@ static NTSTATUS cifspsx_map_fileinfo(struct ntvfs_module_context *ntvfs,
 		short_name = "";
 	}
 
-	asprintf(&pattern, "%s:*", unix_path);
-	
+	ret = asprintf(&pattern, "%s:*", unix_path);
+	if (ret == -1) {
+		return NT_STATUS_NO_MEMORY;
+	}
+
 	if (pattern) {
 		dir = cifspsx_list_unix(req, req, pattern);
 	}
-- 
2.5.5


From aea9045bef1a0daa4cc9797223e0be2087f15b85 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Sat, 26 Mar 2016 02:46:54 +0100
Subject: [PATCH 17/41] s4:ntvfs: fix O3 error unused result of asprintf in
 cifspsx_list_unix

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/ntvfs/cifs_posix_cli/svfs_util.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/source4/ntvfs/cifs_posix_cli/svfs_util.c b/source4/ntvfs/cifs_posix_cli/svfs_util.c
index f351c58..a9e6ba4 100644
--- a/source4/ntvfs/cifs_posix_cli/svfs_util.c
+++ b/source4/ntvfs/cifs_posix_cli/svfs_util.c
@@ -94,6 +94,7 @@ struct cifspsx_dir *cifspsx_list_unix(TALLOC_CTX *mem_ctx, struct ntvfs_request
 		unsigned int i = dir->count;
 		char *full_name;
 		char *low_name;
+		int ret;
 
 		if (strchr(dent->d_name, ':') && !strchr(unix_path, ':')) {
 			/* don't show streams in dir listing */
@@ -120,7 +121,11 @@ struct cifspsx_dir *cifspsx_list_unix(TALLOC_CTX *mem_ctx, struct ntvfs_request
 		dir->files[i].name = low_name;
 		if (!dir->files[i].name) { continue; }
 
-		asprintf(&full_name, "%s/%s", dir->unix_dir, dir->files[i].name);
+		ret = asprintf(&full_name, "%s/%s", dir->unix_dir, dir->files[i].name);
+		if (ret == -1) {
+			continue;
+		}
+
 		if (!full_name) { continue; }
 
 		if (stat(full_name, &dir->files[i].st) == 0) { 
-- 
2.5.5


From 6be6b8a1c4b90296c69201fbdaf361c659231fc2 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 12:18:17 +0200
Subject: [PATCH 18/41] s4:ntvfs: fix O3 error unused result of asprintf in
 cifspsx_file_utime()

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/ntvfs/cifs_posix_cli/svfs_util.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/source4/ntvfs/cifs_posix_cli/svfs_util.c b/source4/ntvfs/cifs_posix_cli/svfs_util.c
index a9e6ba4..cf881a1 100644
--- a/source4/ntvfs/cifs_posix_cli/svfs_util.c
+++ b/source4/ntvfs/cifs_posix_cli/svfs_util.c
@@ -165,7 +165,11 @@ int cifspsx_file_utime(int fd, struct utimbuf *times)
 	char *fd_path = NULL;
 	int ret;
 
-	asprintf(&fd_path, "/proc/self/%d", fd);
+	ret = asprintf(&fd_path, "/proc/self/%d", fd);
+	if (ret == -1) {
+		return -1;
+	}
+
 	if (!fd_path) {
 		errno = ENOMEM;
 		return -1;
-- 
2.5.5


From d38ec90a1f285afe0fbc83d882bc7b5a1fcc0748 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 12:36:57 +0200
Subject: [PATCH 19/41] s4:ntvfs: fix O3 error unused result of write error in
 nbench_log()

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/ntvfs/nbench/vfs_nbench.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source4/ntvfs/nbench/vfs_nbench.c b/source4/ntvfs/nbench/vfs_nbench.c
index e6f725a..c3e0a42 100644
--- a/source4/ntvfs/nbench/vfs_nbench.c
+++ b/source4/ntvfs/nbench/vfs_nbench.c
@@ -26,6 +26,7 @@
 #include "includes.h"
 #include "ntvfs/ntvfs.h"
 #include "system/filesys.h"
+#include "lib/util/sys_rw.h"
 
 NTSTATUS ntvfs_nbench_init(void);
 
@@ -56,7 +57,7 @@ static void nbench_log(struct ntvfs_request *req,
 		return;
 	}
 
-	write(nprivates->log_fd, s, strlen(s));
+	sys_write_v(nprivates->log_fd, s, strlen(s));
 	free(s);
 }
 
-- 
2.5.5


From 17eef089ef355f5184714b0f3c822709f87d252b Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 15:43:52 +0200
Subject: [PATCH 20/41] s4:regshell: fix O3 error unused result of asprintf in
 reg_complete_key()

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/lib/registry/tools/regshell.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c
index 448f957..6b61c92 100644
--- a/source4/lib/registry/tools/regshell.c
+++ b/source4/lib/registry/tools/regshell.c
@@ -482,6 +482,7 @@ static char **reg_complete_key(const char *text, int start, int end)
 	const char *base_n = "";
 	TALLOC_CTX *mem_ctx;
 	WERROR status;
+	int ret;
 
 	matches = malloc_array_p(char *, MAX_COMPLETIONS);
 	if (!matches) return NULL;
@@ -529,12 +530,16 @@ static char **reg_complete_key(const char *text, int start, int end)
 	}
 
 	if (j == 2) { /* Exact match */
-		asprintf(&matches[0], "%s%s", base_n, matches[1]);
+		ret = asprintf(&matches[0], "%s%s", base_n, matches[1]);
 	} else {
-		asprintf(&matches[0], "%s%s", base_n,
+		ret = asprintf(&matches[0], "%s%s", base_n,
 				talloc_strndup(mem_ctx, matches[1], samelen));
 	}
 	talloc_free(mem_ctx);
+	if (ret == -1) {
+		SAFE_FREE(matches);
+		return NULL;
+	}
 
 	matches[j] = NULL;
 	return matches;
-- 
2.5.5


From 814c050275a7cd2f2a1237cf7b4c8f1ba5323396 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 17:15:29 +0200
Subject: [PATCH 21/41] s4:torture:basic: fix O3 error unused result of
 asprintf

in run_opentest()

While fixing this, also convert to using talloc_asprintf instead.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/torture/basic/base.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/source4/torture/basic/base.c b/source4/torture/basic/base.c
index e8ae4b6..3b89c36 100644
--- a/source4/torture/basic/base.c
+++ b/source4/torture/basic/base.c
@@ -823,7 +823,9 @@ static bool run_vuidtest(struct torture_context *tctx,
 	int failures = 0;
 	int i;
 
-	asprintf(&control_char_fname, "\\readonly.afile");
+	control_char_fname = talloc_strdup(tctx, "\\readonly.afile");
+	torture_assert_not_null(tctx, control_char_fname, "asprintf failed\n");
+
 	for (i = 1; i <= 0x1f; i++) {
 		control_char_fname[10] = i;
 		fnum1 = smbcli_nt_create_full(cli1->tree, control_char_fname, 0, SEC_FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
@@ -842,7 +844,7 @@ static bool run_vuidtest(struct torture_context *tctx,
 		smbcli_setatr(cli1->tree, control_char_fname, 0, 0);
 		smbcli_unlink(cli1->tree, control_char_fname);
 	}
-	free(control_char_fname);
+	TALLOC_FREE(control_char_fname);
 
 	if (!failures)
 		torture_comment(tctx, "Create file with control char names passed.\n");
-- 
2.5.5


From 8f10951e151c16421a0e2a93e5f544073dfc9ab8 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 18:14:19 +0200
Subject: [PATCH 22/41] s4:torture:basic:misc: fix O3 error unused result of
 asprintf

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/torture/basic/misc.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/source4/torture/basic/misc.c b/source4/torture/basic/misc.c
index 4e84e38..0a0b0f7 100644
--- a/source4/torture/basic/misc.c
+++ b/source4/torture/basic/misc.c
@@ -70,13 +70,16 @@ static bool rw_torture(struct torture_context *tctx, struct smbcli_state *c)
 
 	for (i=0;i<torture_numops;i++) {
 		unsigned int n = (unsigned int)random()%10;
+		int ret;
+
 		if (i % 10 == 0) {
 			if (torture_setting_bool(tctx, "progress", true)) {
 				torture_comment(tctx, "%d\r", i);
 				fflush(stdout);
 			}
 		}
-		asprintf(&fname, "\\torture.%u", n);
+		ret = asprintf(&fname, "\\torture.%u", n);
+		torture_assert(tctx, ret != -1, "asprintf failed");
 
 		if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
 			return false;
@@ -302,6 +305,7 @@ bool torture_maxfid_test(struct torture_context *tctx, struct smbcli_state *cli)
 	int fnums[0x11000], i;
 	int retries=4, maxfid;
 	bool correct = true;
+	int ret;
 
 	if (retries <= 0) {
 		torture_comment(tctx, "failed to connect\n");
@@ -323,7 +327,8 @@ bool torture_maxfid_test(struct torture_context *tctx, struct smbcli_state *cli)
 
 	for (i=0; i<0x11000; i++) {
 		if (i % 1000 == 0) {
-			asprintf(&fname, "\\maxfid\\fid%d", i/1000);
+			ret = asprintf(&fname, "\\maxfid\\fid%d", i/1000);
+			torture_assert(tctx, ret != -1, "asprintf failed");
 			if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
 				torture_comment(tctx, "Failed to mkdir %s, error=%s\n", 
 				       fname, smbcli_errstr(cli->tree));
@@ -331,7 +336,8 @@ bool torture_maxfid_test(struct torture_context *tctx, struct smbcli_state *cli)
 			}
 			free(fname);
 		}
-		asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
+		ret = asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
+		torture_assert(tctx, ret != -1, "asprintf failed");
 		if ((fnums[i] = smbcli_open(cli->tree, fname, 
 					O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
 		    -1) {
@@ -352,7 +358,8 @@ bool torture_maxfid_test(struct torture_context *tctx, struct smbcli_state *cli)
 
 	torture_comment(tctx, "cleaning up\n");
 	for (i=0;i<maxfid;i++) {
-		asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
+		ret = asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
+		torture_assert(tctx, ret != -1, "asprintf failed");
 		if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
 			torture_comment(tctx, "Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
 		}
-- 
2.5.5


From 0d3ed5b2b78fd1614ca70bf5ba3dd90464120639 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 18:16:46 +0200
Subject: [PATCH 23/41] s4:torture:basic: fix O3 error unused result of write

in test_utable

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/torture/basic/utable.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source4/torture/basic/utable.c b/source4/torture/basic/utable.c
index 0b45692..da2fe2e 100644
--- a/source4/torture/basic/utable.c
+++ b/source4/torture/basic/utable.c
@@ -24,6 +24,7 @@
 #include "torture/util.h"
 #include "param/param.h"
 #include "torture/basic/proto.h"
+#include "lib/util/sys_rw.h"
 
 bool torture_utable(struct torture_context *tctx, 
 					struct smbcli_state *cli)
@@ -96,7 +97,7 @@ bool torture_utable(struct torture_context *tctx,
 	torture_assert(tctx, fd != -1, 
 		talloc_asprintf(tctx, 
 		"Failed to create valid.dat - %s", strerror(errno)));
-	write(fd, valid, 0x10000);
+	sys_write_v(fd, valid, 0x10000);
 	close(fd);
 	torture_comment(tctx, "wrote valid.dat\n");
 
-- 
2.5.5


From e48f98f54a7ac124b4084c7052c9de42f934ca4e Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 18:19:30 +0200
Subject: [PATCH 24/41] s4:torture:basic:dir: fix O3 error unused result of
 asprintf

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/torture/basic/dir.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/source4/torture/basic/dir.c b/source4/torture/basic/dir.c
index 774730a..2a3d136 100644
--- a/source4/torture/basic/dir.c
+++ b/source4/torture/basic/dir.c
@@ -41,6 +41,7 @@ bool torture_dirtest1(struct torture_context *tctx,
 	bool correct = true;
 	extern int torture_numops;
 	struct timeval tv;
+	int ret;
 
 	torture_comment(tctx, "Creating %d random filenames\n", torture_numops);
 
@@ -48,7 +49,8 @@ bool torture_dirtest1(struct torture_context *tctx,
 	tv = timeval_current();
 	for (i=0;i<torture_numops;i++) {
 		char *fname;
-		asprintf(&fname, "\\%x", (int)random());
+		ret = asprintf(&fname, "\\%x", (int)random());
+		torture_assert(tctx, ret != -1, "asprintf failed");
 		fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
 		if (fnum == -1) {
 			fprintf(stderr,"(%s) Failed to open %s\n", 
@@ -68,7 +70,8 @@ bool torture_dirtest1(struct torture_context *tctx,
 	srandom(0);
 	for (i=0;i<torture_numops;i++) {
 		char *fname;
-		asprintf(&fname, "\\%x", (int)random());
+		ret = asprintf(&fname, "\\%x", (int)random());
+		torture_assert(tctx, ret != -1, "asprintf failed");
 		smbcli_unlink(cli->tree, fname);
 		free(fname);
 	}
@@ -83,6 +86,7 @@ bool torture_dirtest2(struct torture_context *tctx,
 	int fnum, num_seen;
 	bool correct = true;
 	extern int torture_entries;
+	int ret;
 
 	if (!torture_setup_dir(cli, "\\LISTDIR")) {
 		return false;
@@ -93,7 +97,8 @@ bool torture_dirtest2(struct torture_context *tctx,
 	/* Create torture_entries files and torture_entries directories. */
 	for (i=0;i<torture_entries;i++) {
 		char *fname;
-		asprintf(&fname, "\\LISTDIR\\f%d", i);
+		ret = asprintf(&fname, "\\LISTDIR\\f%d", i);
+		torture_assert(tctx, ret != -1, "asprintf failed");
 		fnum = smbcli_nt_create_full(cli->tree, fname, 0, 
 					     SEC_RIGHTS_FILE_ALL,
 					     FILE_ATTRIBUTE_ARCHIVE,
@@ -109,7 +114,8 @@ bool torture_dirtest2(struct torture_context *tctx,
 	}
 	for (i=0;i<torture_entries;i++) {
 		char *fname;
-		asprintf(&fname, "\\LISTDIR\\d%d", i);
+		ret = asprintf(&fname, "\\LISTDIR\\d%d", i);
+		torture_assert(tctx, ret != -1, "asprintf failed");
 		if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
 			fprintf(stderr,"(%s) Failed to open %s, error=%s\n", 
 				__location__, fname, smbcli_errstr(cli->tree));
-- 
2.5.5


From dcfc39451d4342c2f391efdbfdab6531a0fb494e Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 18:21:17 +0200
Subject: [PATCH 25/41] s4:torture:basic:delete: fix O3 error unused result of
 asprintf

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/torture/basic/delete.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/source4/torture/basic/delete.c b/source4/torture/basic/delete.c
index e3d830d..76a83df 100644
--- a/source4/torture/basic/delete.c
+++ b/source4/torture/basic/delete.c
@@ -1760,6 +1760,7 @@ static bool deltest20(struct torture_context *tctx, struct smbcli_state *cli1, s
 	int dnum1 = -1;
 	bool correct = true;
 	NTSTATUS status;
+	int ret;
 
 	del_clean_area(cli1, cli2);
 
@@ -1789,7 +1790,8 @@ static bool deltest20(struct torture_context *tctx, struct smbcli_state *cli1, s
 
 	{
 		char *fullname;
-		asprintf(&fullname, "\\%s%s", dname, fname);
+		ret = asprintf(&fullname, "\\%s%s", dname, fname);
+		torture_assert(tctx, ret != -1, "asprintf failed");
 		fnum1 = smbcli_open(cli1->tree, fullname, O_CREAT|O_RDWR,
 				    DENY_NONE);
 		torture_assert(tctx, fnum1 == -1, 
@@ -1809,7 +1811,8 @@ static bool deltest20(struct torture_context *tctx, struct smbcli_state *cli1, s
 		
 	{
 		char *fullname;
-		asprintf(&fullname, "\\%s%s", dname, fname);
+		ret = asprintf(&fullname, "\\%s%s", dname, fname);
+		torture_assert(tctx, ret != -1, "asprintf failed");
 		fnum1 = smbcli_open(cli1->tree, fullname, O_CREAT|O_RDWR,
 				    DENY_NONE);
 		torture_assert(tctx, fnum1 != -1, 
-- 
2.5.5


From f6e65a42a33ccafe4674b4fc42534f83c03b0b97 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 18:33:59 +0200
Subject: [PATCH 26/41] s4:torture:rpc:samlogon: fix O3 error unused result of
 asprintf

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/torture/rpc/samlogon.c | 49 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 7 deletions(-)

diff --git a/source4/torture/rpc/samlogon.c b/source4/torture/rpc/samlogon.c
index 4465698..cefc4f5 100644
--- a/source4/torture/rpc/samlogon.c
+++ b/source4/torture/rpc/samlogon.c
@@ -346,8 +346,13 @@ static bool test_lm_ntlm_broken(struct samlogon_state *samlogon_state, enum ntlm
 	} else if (NT_STATUS_EQUAL(NT_STATUS_NOT_FOUND, nt_status) && strchr_m(samlogon_state->account_name, '@')) {
 		return ((break_which == BREAK_NT) || (break_which == BREAK_BOTH) || (break_which == NO_NT));
 	} else if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
+		int ret;
+
 		SAFE_FREE(*error_string);
-		asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		ret = asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		if (ret == -1) {
+			*error_string = NULL;
+		}
 		return false;
 	} else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
 		return true;
@@ -467,8 +472,13 @@ static bool test_ntlm_in_lm(struct samlogon_state *samlogon_state, char **error_
 		}
 		return false;
 	} else if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
+		int ret;
+
 		SAFE_FREE(*error_string);
-		asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		ret = asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		if (ret == -1) {
+			*error_string = NULL;
+		}
 		return false;
 	} else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
 		return true;
@@ -564,8 +574,13 @@ static bool test_ntlm_in_both(struct samlogon_state *samlogon_state, char **erro
 		}
 		return false;
 	} else if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
+		int ret;
+
 		SAFE_FREE(*error_string);
-		asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		ret = asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		if (ret == -1) {
+			*error_string = NULL;
+		}
 		return false;
 	} else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
 		return true;
@@ -677,8 +692,13 @@ static bool test_lmv2_ntlmv2_broken(struct samlogon_state *samlogon_state,
 	} else if (NT_STATUS_EQUAL(NT_STATUS_NOT_FOUND, nt_status) && strchr_m(samlogon_state->account_name, '@')) {
 		return ((break_which == BREAK_NT) || (break_which == BREAK_BOTH) || (break_which == NO_NT));
 	} else if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
+		int ret;
+
 		SAFE_FREE(*error_string);
-		asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		ret = asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		if (ret == -1) {
+			*error_string = NULL;
+		}
 		return false;
 	} else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
 		return true;
@@ -845,8 +865,13 @@ static bool test_lmv2_ntlm_broken(struct samlogon_state *samlogon_state,
 	} else if (NT_STATUS_EQUAL(NT_STATUS_NOT_FOUND, nt_status) && strchr_m(samlogon_state->account_name, '@')) {
 		return ((break_which == BREAK_NT) || (break_which == BREAK_BOTH));
 	} else if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
+		int ret;
+
 		SAFE_FREE(*error_string);
-		asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		ret = asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		if (ret == -1) {
+			*error_string = NULL;
+		}
 		return false;
 	} else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
 		return true;
@@ -1126,8 +1151,13 @@ static bool test_ntlm2(struct samlogon_state *samlogon_state, char **error_strin
 		}
 		return false;
 	} else if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
+		int ret;
+
 		SAFE_FREE(*error_string);
-		asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		ret = asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		if (ret == -1) {
+			*error_string = NULL;
+		}
 		return false;
 	} else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
 		return true;
@@ -1229,8 +1259,13 @@ static bool test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_brea
 	} else if (NT_STATUS_EQUAL(NT_STATUS_NOT_FOUND, nt_status) && strchr_m(samlogon_state->account_name, '@')) {
 		return ((break_which == BREAK_NT) || (break_which == BREAK_BOTH) || (break_which == NO_NT));
 	} else if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
+		int ret;
+
 		SAFE_FREE(*error_string);
-		asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		ret = asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
+		if (ret == -1) {
+			*error_string = NULL;
+		}
 		return false;
 	} else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
 		return true;
-- 
2.5.5


From 843068dde4f83d3aec41026445809688545e4d38 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 18:52:29 +0200
Subject: [PATCH 27/41] s4:torture:nbench: fix O3 error unused result of
 asprintf

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/torture/nbench/nbench.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/source4/torture/nbench/nbench.c b/source4/torture/nbench/nbench.c
index 3258e19..2f10435 100644
--- a/source4/torture/nbench/nbench.c
+++ b/source4/torture/nbench/nbench.c
@@ -64,6 +64,7 @@ static bool run_netbench(struct torture_context *tctx, struct smbcli_state *cli,
 	bool correct = true;
 	double target_rate = torture_setting_double(tctx, "targetrate", 0);	
 	int n = 0;
+	int ret;
 
 	if (target_rate != 0 && client == 0) {
 		printf("Targeting %.4f MByte/sec\n", target_rate);
@@ -77,7 +78,10 @@ static bool run_netbench(struct torture_context *tctx, struct smbcli_state *cli,
 		}
 	}
 
-	asprintf(&cname, "client%d", client+1);
+	ret = asprintf(&cname, "client%d", client+1);
+	if (ret == -1) {
+		return false;
+	}
 
 	f = fopen(loadfile, "r");
 
-- 
2.5.5


From 3c368147dd832edcbe5fe9eec8f5db48b10505e9 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 19:26:41 +0200
Subject: [PATCH 28/41] s4:client: fix O3 error unused result of of chdir and
 system

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source4/client/client.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/source4/client/client.c b/source4/client/client.c
index a069443..4807123 100644
--- a/source4/client/client.c
+++ b/source4/client/client.c
@@ -874,6 +874,7 @@ static void do_mget(struct smbclient_context *ctx, struct clilist_file_info *fin
 	char *mget_mask;
 	char *saved_curdir;
 	char *l_fname;
+	int ret;
 
 	if (ISDOT(finfo->name) || ISDOTDOT(finfo->name))
 		return;
@@ -922,7 +923,11 @@ static void do_mget(struct smbclient_context *ctx, struct clilist_file_info *fin
 	mget_mask = talloc_asprintf(ctx, "%s*", ctx->remote_cur_dir);
 	
 	do_list(ctx, mget_mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,do_mget,false, true);
-	chdir("..");
+	ret = chdir("..");
+	if (ret == -1) {
+		d_printf("failed to chdir to '..': %s\n", strerror(errno));
+		return;
+	}
 	talloc_free(ctx->remote_cur_dir);
 
 	ctx->remote_cur_dir = saved_curdir;
@@ -965,7 +970,11 @@ static int cmd_more(struct smbclient_context *ctx, const char **args)
 	pager=getenv("PAGER");
 
 	pager_cmd = talloc_asprintf(ctx, "%s %s",(pager? pager:DEFAULT_PAGER), lname);
-	system(pager_cmd);
+	rc = system(pager_cmd);
+	if (rc == -1) {
+		d_printf("failed to call pager command\n");
+		return 1;
+	}
 	unlink(lname);
 	
 	return rc;
@@ -2540,8 +2549,17 @@ static int cmd_lcd(struct smbclient_context *ctx, const char **args)
 {
 	char d[PATH_MAX];
 	
-	if (args[1]) 
-		chdir(args[1]);
+	if (args[1]) {
+		int ret;
+
+		ret = chdir(args[1]);
+		if (ret == -1) {
+			d_printf("failed to chdir to dir '%s': %s\n",
+				 args[1], strerror(errno));
+			return 1;
+		}
+	}
+
 	DEBUG(2,("the local directory is now %s\n",getcwd(d, PATH_MAX)));
 
 	return 0;
@@ -3138,8 +3156,12 @@ static int process_stdin(struct smbclient_context *ctx)
 
 		/* special case - first char is ! */
 		if (*cline == '!') {
-			system(cline + 1);
+			int ret;
+			ret = system(cline + 1);
 			free(cline);
+			if (ret == -1) {
+				rc |= ret;
+			}
 			continue;
 		}
 
-- 
2.5.5


From ce5f1343dbc1ebde367df875980c5295253b3676 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 16:47:39 +0200
Subject: [PATCH 29/41] s3:samlogon_cache: fix O3 error unused result of
 truncate

in netsamlogon_cache_init()

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source3/libsmb/samlogon_cache.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/source3/libsmb/samlogon_cache.c b/source3/libsmb/samlogon_cache.c
index c408082..7be5479 100644
--- a/source3/libsmb/samlogon_cache.c
+++ b/source3/libsmb/samlogon_cache.c
@@ -77,7 +77,13 @@ clear:
 	first_try = false;
 
 	DEBUG(0,("retry after truncate for '%s'\n", path));
-	truncate(path, 0);
+	ret = truncate(path, 0);
+	if (ret == -1) {
+		DBG_ERR("truncate failed: %s\n", strerror(errno));
+		talloc_free(path);
+		return false;
+	}
+
 	goto again;
 }
 
-- 
2.5.5


From d490e53a0c4eb4216d39209f7531160ff8b5143e Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 19:56:25 +0200
Subject: [PATCH 30/41] s3:utils:log2pcaphex: fix O3 error unused result of
 fgets

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source3/utils/log2pcaphex.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c
index 23526c2..2d68db6 100644
--- a/source3/utils/log2pcaphex.c
+++ b/source3/utils/log2pcaphex.c
@@ -350,7 +350,13 @@ int main(int argc, const char **argv)
 	if(!hexformat)print_pcap_header(out);
 
 	while(!feof(in)) {
-		fgets(buffer, sizeof(buffer), in); line_num++;
+		char *p;
+		p = fgets(buffer, sizeof(buffer), in);
+		if (p == NULL) {
+			fprintf(stderr, "error reading from input file\n");
+			break;
+		}
+		line_num++;
 		if(buffer[0] == '[') { /* Header */
 			if(strstr(buffer, "show_msg")) {
 				in_packet++;
-- 
2.5.5


From 39ec7b084c663a5d05dd1e97a7780db6585fb2be Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 19:57:42 +0200
Subject: [PATCH 31/41] s3:utils:log2pcaphex: fix O3 error uninitialized
 variable

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source3/utils/log2pcaphex.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c
index 2d68db6..f31efa1 100644
--- a/source3/utils/log2pcaphex.c
+++ b/source3/utils/log2pcaphex.c
@@ -302,7 +302,8 @@ int main(int argc, const char **argv)
 	int opt;
 	poptContext pc;
 	char buffer[4096];
-	long data_offset, data_length;
+	long data_offset = 0;
+	long data_length;
 	long data_bytes_read = 0;
 	int in_packet = 0;
 	struct poptOption long_options[] = {
-- 
2.5.5


From 1520a1b86f6de2531d3b9a7d37c712b084b9cf55 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 20:01:32 +0200
Subject: [PATCH 32/41] s3:smbfilter: fix O3 error unused result of system()

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source3/utils/smbfilter.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c
index 9068448..5a00a40 100644
--- a/source3/utils/smbfilter.c
+++ b/source3/utils/smbfilter.c
@@ -88,6 +88,7 @@ static void filter_request(char *buf, size_t buf_len)
 	int name_len1 = 0;
 	int name_len2;
 	int name_type1, name_type2;
+	int ret;
 
 	if (msg_type) {
 		/* it's a netbios special */
@@ -142,7 +143,10 @@ static void filter_request(char *buf, size_t buf_len)
 		x = IVAL(buf,smb_vwv11);
 		d_printf("SMBsesssetupX cap=0x%08x\n", x);
 		d_printf("pwlen=%d/%d\n", SVAL(buf, smb_vwv7), SVAL(buf, smb_vwv8));
-		system("mv sessionsetup.dat sessionsetup1.dat");
+		ret = system("mv sessionsetup.dat sessionsetup1.dat");
+		if (ret == -1) {
+			DBG_ERR("failed to call mv command\n");
+		}
 		save_file("sessionsetup.dat", smb_buf(buf), SVAL(buf, smb_vwv7));
 		x = (x | CLI_CAPABILITY_SET) & ~CLI_CAPABILITY_MASK;
 		SIVAL(buf, smb_vwv11, x);
-- 
2.5.5


From d4d308703dc22dff1d51aa273ed35c64b57b15de Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 22:21:19 +0200
Subject: [PATCH 33/41] s3:vfs:aio_fork: fix O3 error unused result of write

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source3/modules/vfs_aio_fork.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
index e699fc5..7d06b98 100644
--- a/source3/modules/vfs_aio_fork.c
+++ b/source3/modules/vfs_aio_fork.c
@@ -411,7 +411,7 @@ static int aio_child_destructor(struct aio_child *child)
 	 * closing the sockfd makes the child not return from recvmsg() on RHEL
 	 * 5.5 so instead force the child to exit by writing bad data to it
 	 */
-	write(child->sockfd, &c, sizeof(c));
+	sys_write_v(child->sockfd, &c, sizeof(c));
 	close(child->sockfd);
 	DLIST_REMOVE(child->list->children, child);
 	return 0;
-- 
2.5.5


From 2ffd9ffb454b6ac60659fbd20ba9ca359aa9a73b Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 22:22:47 +0200
Subject: [PATCH 34/41] s3:vfs:preopen: fix O3 error unused result of write

(void) cast is not enough.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source3/modules/vfs_preopen.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source3/modules/vfs_preopen.c b/source3/modules/vfs_preopen.c
index b67aad8..8bf30b6 100644
--- a/source3/modules/vfs_preopen.c
+++ b/source3/modules/vfs_preopen.c
@@ -21,6 +21,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "smbd/smbd.h"
+#include "lib/util/sys_rw.h"
 #include "lib/util/sys_rw_data.h"
 
 struct preopen_state;
@@ -185,7 +186,7 @@ static bool preopen_helper_open_one(int sock_fd, char **pnamebuf,
 	close(fd);
 
  done:
-	(void)write(sock_fd, &c, 1);
+	sys_write_v(sock_fd, &c, 1);
 	return true;
 }
 
-- 
2.5.5


From 92ce9bcd6cfa57ca87063df1f021052f6ee6c577 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 22:34:32 +0200
Subject: [PATCH 35/41] examples:smbclient:testacl3: fix O3 error unused result
 from fgets

Signed-off-by: Michael Adam <obnox at samba.org>
---
 examples/libsmbclient/testacl3.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/libsmbclient/testacl3.c b/examples/libsmbclient/testacl3.c
index f34e273..59d9994 100644
--- a/examples/libsmbclient/testacl3.c
+++ b/examples/libsmbclient/testacl3.c
@@ -27,7 +27,11 @@ int main(int argc, char * argv[])
     {
         fprintf(stdout, "Path: ");
         *path = '\0';
-        fgets(path, sizeof(path) - 1, stdin);
+        p = fgets(path, sizeof(path) - 1, stdin);
+	if (p == NULL) {
+		printf("Error reading from stdin\n");
+		return 1;
+	}
         if (strlen(path) == 0)
         {
             return 0;
-- 
2.5.5


From 00bc42d645250477952a3ddd646afa9a5799ac32 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 22:36:34 +0200
Subject: [PATCH 36/41] examples:smbclient:notify: fix O3 error unused result
 from fgets

Signed-off-by: Michael Adam <obnox at samba.org>
---
 examples/libsmbclient/testnotify.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/libsmbclient/testnotify.c b/examples/libsmbclient/testnotify.c
index 68513af..8760cf0 100644
--- a/examples/libsmbclient/testnotify.c
+++ b/examples/libsmbclient/testnotify.c
@@ -43,7 +43,11 @@ int main(int argc, char * argv[])
 
 	fprintf(stdout, "Path: ");
 	*path = '\0';
-	fgets(path, sizeof(path) - 1, stdin);
+	p = fgets(path, sizeof(path) - 1, stdin);
+	if (p == NULL) {
+		fprintf(stderr, "error reading from stdin\n");
+		return 1;
+	}
 	if (strlen(path) == 0) {
 		return 0;
 	}
-- 
2.5.5


From a86dc836eb3ce066337ccbf6fe26c4c962703d8e Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 22:50:52 +0200
Subject: [PATCH 37/41] examples:smbclient:statvfs: fix O3 error unused result
 of fgets

Signed-off-by: Michael Adam <obnox at samba.org>
---
 examples/libsmbclient/teststatvfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/libsmbclient/teststatvfs.c b/examples/libsmbclient/teststatvfs.c
index 2f656d5..9a8e539 100644
--- a/examples/libsmbclient/teststatvfs.c
+++ b/examples/libsmbclient/teststatvfs.c
@@ -23,7 +23,11 @@ int main(int argc, char * argv[])
     {
         fprintf(stdout, "Path: ");
         *path = '\0';
-        fgets(path, sizeof(path) - 1, stdin);
+	p = fgets(path, sizeof(path) - 1, stdin);
+	if (p == NULL) {
+		fprintf(stderr, "failed to read from stdin\n");
+		return 1;
+	}
         if (strlen(path) == 0)
         {
             return 0;
-- 
2.5.5


From 64eac4e2afea20a52a97533e48ef1be43b0cad30 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 22:55:01 +0200
Subject: [PATCH 38/41] examples:smbclient:fstatvfs: fix O3 error unused result
 of fgets

Signed-off-by: Michael Adam <obnox at samba.org>
---
 examples/libsmbclient/testfstatvfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/libsmbclient/testfstatvfs.c b/examples/libsmbclient/testfstatvfs.c
index 512563f..b2396e3 100644
--- a/examples/libsmbclient/testfstatvfs.c
+++ b/examples/libsmbclient/testfstatvfs.c
@@ -25,7 +25,11 @@ int main(int argc, char * argv[])
     {
         fprintf(stdout, "Path: ");
         *path = '\0';
-        fgets(path, sizeof(path) - 1, stdin);
+	p = fgets(path, sizeof(path) - 1, stdin);
+	if (p == NULL) {
+		fprintf(stderr, "failed to read from stdin\n");
+		return 1;
+	}
         if (strlen(path) == 0)
         {
             return 0;
-- 
2.5.5


From 6d209dbe89b902ac22e0138bc728aed8d4afab91 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 22:57:51 +0200
Subject: [PATCH 39/41] examples:smbclient:read: fix O3 error unused result of
 fgets

Signed-off-by: Michael Adam <obnox at samba.org>
---
 examples/libsmbclient/testread.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/libsmbclient/testread.c b/examples/libsmbclient/testread.c
index 87625e8..e6d9bf8 100644
--- a/examples/libsmbclient/testread.c
+++ b/examples/libsmbclient/testread.c
@@ -24,7 +24,11 @@ int main(int argc, char * argv[])
     {
         fprintf(stdout, "Path: ");
         *path = '\0';
-        fgets(path, sizeof(path) - 1, stdin);
+	p = fgets(path, sizeof(path) - 1, stdin);
+	if (p == NULL) {
+		fprintf(stderr, "failed to read from stdin\n");
+		return 1;
+	}
         if (strlen(path) == 0)
         {
             return 0;
-- 
2.5.5


From 015903069e16e84efa6dbda964837a746a15eb24 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 5 Apr 2016 23:07:11 +0200
Subject: [PATCH 40/41] examples:smbclient:write: fix O3 error unused result of
 fgets

Signed-off-by: Michael Adam <obnox at samba.org>
---
 examples/libsmbclient/testwrite.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/examples/libsmbclient/testwrite.c b/examples/libsmbclient/testwrite.c
index 636cb20..1837839 100644
--- a/examples/libsmbclient/testwrite.c
+++ b/examples/libsmbclient/testwrite.c
@@ -22,14 +22,22 @@ int main(int argc, char * argv[])
     
     printf("CAUTION: This program will overwrite a file.  "
            "Press ENTER to continue.");
-    fgets(buffer, sizeof(buffer), stdin);
+    p = fgets(buffer, sizeof(buffer), stdin);
+    if (p == NULL) {
+        fprintf(stderr, "failed to read from stdin\n");
+        return 1;
+    }
            
 
     for (;;)
     {
         fprintf(stdout, "\nPath: ");
         *path = '\0';
-        fgets(path, sizeof(path) - 1, stdin);
+        p = fgets(path, sizeof(path) - 1, stdin);
+        if (p == NULL) {
+            fprintf(stderr, "failed to read from stdin\n");
+            return 1;
+        }
         if (strlen(path) == 0)
         {
             return 0;
-- 
2.5.5


From 3aa21c546d452fdae8dfd6bb63c1422341436fdc Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Mon, 11 Apr 2016 10:23:00 +0200
Subject: [PATCH 41/41] autobuild: run the samba-o3 target by default

Signed-off-by: Michael Adam <obnox at samba.org>
---
 script/autobuild.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/script/autobuild.py b/script/autobuild.py
index 6b7eca2..726ce59 100755
--- a/script/autobuild.py
+++ b/script/autobuild.py
@@ -39,7 +39,7 @@ builddirs = {
     "retry"   : "."
     }
 
-defaulttasks = [ "ctdb", "samba", "samba-xc", "samba-ctdb", "samba-libs", "samba-static", "ldb", "tdb", "talloc", "replace", "tevent", "pidl" ]
+defaulttasks = [ "ctdb", "samba", "samba-xc", "samba-o3", "samba-ctdb", "samba-libs", "samba-static", "ldb", "tdb", "talloc", "replace", "tevent", "pidl" ]
 
 samba_configure_params = " --picky-developer ${PREFIX} ${EXTRA_PYTHON} --with-profiling-data"
 
-- 
2.5.5

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160411/595dc732/signature.sig>


More information about the samba-technical mailing list