From: Andre Noll <maan@systemlinux.org>
Date: Wed, 12 Sep 2007 21:43:16 +0000 (+0200)
Subject: aft.c: Fix com_add().
X-Git-Tag: v0.3.0~423
X-Git-Url: https://git.tuebingen.mpg.de/?a=commitdiff_plain;h=d330cf697501c14bb696256cb27c9e69b9edf3f4;p=paraslash.git

aft.c: Fix com_add().

callbacks shall return zero or negative, if no result is provided. So let
com_ls_callback() return zero if no match was found, or if the audio file table
does not contain any entries. Check for ret > 0 in com_add() instead of ret >=
0, i.e. don't use the result pointer if ret is zero.
---

diff --git a/aft.c b/aft.c
index 3c33aae0..9ec97761 100644
--- a/aft.c
+++ b/aft.c
@@ -981,7 +981,7 @@ static int com_ls_callback(const struct osl_object *query,
 			prepare_ls_row);
 	if (ret < 0)
 		goto out;
-	ret = opts->num_patterns? -E_NO_MATCH : 1;
+	ret = opts->num_patterns? -E_NO_MATCH : 0;
 	if (!opts->num_matching_paths) {
 		PARA_NOTICE_LOG("no match, ret: %d\n", ret);
 		goto out;
@@ -1004,6 +1004,7 @@ static int com_ls_callback(const struct osl_object *query,
 	ret = 1;
 out:
 	ls_output->data = b.buf;
+	PARA_NOTICE_LOG("ls_outoute.data: %p\n", ls_output->data);
 	ls_output->size = b.size;
 	free(opts->data);
 	free(opts->data_ptr);
@@ -1123,8 +1124,8 @@ int com_afs_ls(int fd, int argc, char * const * const argv)
 	opts.num_patterns = argc - i;
 	ret = send_option_arg_callback_request(&query, opts.num_patterns,
 		argv + i, com_ls_callback, &ls_output);
-	if (ret >= 0 && ls_output.data) {
-		send_buffer(fd, (char *)ls_output.data);
+	if (ret > 0) {
+		ret = send_buffer(fd, (char *)ls_output.data);
 		free(ls_output.data);
 	}
 	return ret;