Only in xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient: #xmmsclient.c#
diff -ur xmms2.git-snapshot-200507282137-org/src/clients/lib/xmmsclient/medialib.c xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient/medialib.c
--- xmms2.git-snapshot-200507282137-org/src/clients/lib/xmmsclient/medialib.c	2005-07-29 01:38:31.000000000 +0300
+++ xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient/medialib.c	2005-07-29 03:47:16.000000000 +0300
@@ -79,7 +79,7 @@
 char *
 xmmsc_sqlite_prepare_string (char *input) {
 	char *output;
-	int outsize, nquotes=0;
+	int outsize, nquotes = 0;
 	int i, o;
 
 	for (i = 0; input[i] != '\0'; i++) {
@@ -87,11 +87,12 @@
 			nquotes++;
 		}
 	}
-	
+
 	outsize = strlen(input) + nquotes + 2 + 1; /* 2 quotes to terminate the string , and one \0 in the end */
-	output = (char*) malloc(outsize);
+	output = malloc(outsize);
 
 	if (output == NULL) {
+		x_oom();
 		return NULL;
 	}
 	
@@ -120,37 +121,36 @@
 xmmsc_querygen_fill_template (templ_type idx, xmmsc_query_attribute_t *attributes, unsigned i)
 {
 	int res_size = 0;
-	char *res = NULL;
-	char *tbuf = (char*) malloc(sizeof(char));
-	if (tbuf == NULL) {
-		return NULL;
-	}
+	char *res;
+	char t;
 
 	switch (idx) {
 	case templ_key:
-		res_size = snprintf(tbuf, 1, constraint_templates[templ_key], i, attributes[i].key);
+		res_size = snprintf(&t, 1, constraint_templates[templ_key], i, attributes[i].key);
 		break;
 	case templ_value:
-		res_size = snprintf(tbuf, 1, constraint_templates[templ_value], i, attributes[i].value);
+		res_size = snprintf(&t, 1, constraint_templates[templ_value], i, attributes[i].value);
 		break;
 	case templ_id:
-		res_size = snprintf(tbuf, 1, constraint_templates[templ_id], i-1, i);
+		res_size = snprintf(&t, 1, constraint_templates[templ_id], i-1, i);
 		break;
 	case templ_table:
-		res_size = snprintf(tbuf, 1, constraint_templates[templ_table], i);
+		res_size = snprintf(&t, 1, constraint_templates[templ_table], i);
 		break;
+	default:
+		/* do we need a default error case? */
 	}
-	free(tbuf);
-	
+
 	res_size += 1;
-	
+
 	res = malloc(res_size);
 	if (res == NULL) {
+		x_oom();
 		return NULL;
 	}
 
 
-	switch(idx) {
+	switch (idx) {
 	case templ_key:
 		snprintf(res, res_size, constraint_templates[templ_key], i, attributes[i].key);
 		break;
@@ -177,22 +177,21 @@
 xmmsc_querygen_parse_constraints (char **pconstraints, xmmsc_query_attribute_t *attributes, unsigned n) {
 	int success = 1, tmp_size;
 	char *oconstraints = NULL;
-	char *constraints = NULL;
-	char *initconstraints = " WHERE ";
+	char *constraints;
 	char *tmp = NULL;
 	unsigned i;
 	templ_type template;
 	unsigned size = 0;	
-	
-	constraints = (char*) malloc(strlen(initconstraints+1));
+
+	constraints = strdup(" WHERE ");
 
 	if (constraints == NULL) {
+		x_oom();
 		success = 0;
 	} else {
-		strcpy(constraints, initconstraints);
-		size = strlen(constraints)+1;
+		size = strlen(constraints) + 1;
 	}
-	
+
 	if (success) {
 		for (i = 0; i < n; i++) {
 			for (template = templ_key; template <= templ_id; template++) {				
@@ -239,8 +238,7 @@
 int
 xmmsc_querygen_parse_tables (char **ptables, xmmsc_query_attribute_t *attributes, unsigned n) {
 	int success = 1;
-	char *otables = NULL;
-	char *tables = NULL;
+	char *tables;
 	char *tmp = NULL;
 	unsigned i;
 	unsigned size = 1; // make space for the terminating null byte
@@ -249,6 +247,7 @@
 
 	tables = malloc(1);
 	if (tables == NULL) {
+		x_oom();
 		success = 0;
 	} else {
 		tables[0] = '\0';
@@ -256,6 +255,7 @@
 	
 	if (success) {
 		for (i = 0; i < n; i++) {
+			char *otables;
 
 			tmp = xmmsc_querygen_fill_template(templ_table, attributes, i);
 			if (tmp == NULL) {
@@ -267,9 +267,10 @@
 
 			size += tmp_size + (i==0 ? 0 : 2); /* space for ", " */
 			otables = tables;
-			tables = (char*) realloc(tables, size);
+			tables = realloc(tables, size);
 
 			if (tables == NULL) {
+				x_oom();
 				success = 0;
 				free(otables);
 				break;
@@ -302,17 +303,18 @@
 char *
 xmmsc_querygen_and (xmmsc_query_attribute_t *attributes, unsigned n)
 {	
-	char **tables;
-	char **constraints;
+	char **tables = NULL;
+	char **constraints = NULL;
 	int success = 1, fullsize;
 	char *query;
 
 	const char *initquery = "SELECT DISTINCT m0.id FROM ";
 
 	if (success) {
-		tables = (char**) malloc(sizeof(char**));
-		constraints = (char**) malloc(sizeof(char**));
+		tables =  malloc(sizeof(char **));
+		constraints = malloc(sizeof(char **));
 		if (tables == NULL || constraints == NULL) {
+			x_oom();
 			free(tables);
 			free(constraints);
 			success = 0;
@@ -326,8 +328,9 @@
 
 	if (success) {
 		fullsize = strlen(initquery) + strlen(*tables) + strlen(*constraints) + 1;
-		query = (char*) malloc(fullsize);
+		query = malloc(fullsize);
 		if (query == NULL) {
+			x_oom();
 			success = 0;
 		}
 	}
Only in xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient: medialib.c~
diff -ur xmms2.git-snapshot-200507282137-org/src/clients/lib/xmmsclient/result.c xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient/result.c
--- xmms2.git-snapshot-200507282137-org/src/clients/lib/xmmsclient/result.c	2005-07-29 01:38:31.000000000 +0300
+++ xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient/result.c	2005-07-29 03:45:28.000000000 +0300
@@ -299,15 +299,13 @@
 	switch (type) {
 
 		case XMMS_OBJECT_CMD_ARG_UINT32 :
-			{
-				if (!xmms_ipc_msg_get_uint32 (msg, &res->data.uint))
-					return false;
+			if (!xmms_ipc_msg_get_uint32 (msg, &res->data.uint)) {
+				return false;
 			}
 			break;
 		case XMMS_OBJECT_CMD_ARG_INT32 :
-			{
-				if (!xmms_ipc_msg_get_int32 (msg, &res->data.inte))
-					return false;
+			if (!xmms_ipc_msg_get_int32 (msg, &res->data.inte)) {
+				return false;
 			}
 			break;
 		case XMMS_OBJECT_CMD_ARG_STRING :
@@ -379,8 +377,9 @@
 int
 xmmsc_result_cid (xmmsc_result_t *res)
 {
-	if (!res)
+	if (!res) {
 		return 0;
+	}
 
 	return res->cid;
 }
@@ -434,10 +433,10 @@
 void
 xmmsc_result_wait (xmmsc_result_t *res)
 {
-	const char *err;
+	char *err = NULL;
 	x_return_if_fail (res);
 
-	while (!res->parsed && !(err =xmmsc_ipc_error_get (res->ipc))) {
+	while (!res->parsed && !(err = xmmsc_ipc_error_get (res->ipc))) {
 		xmmsc_ipc_wait_for_event (res->ipc, 5);
 	}
 
@@ -504,8 +503,9 @@
 		return 0;
 	}
 
-	if (res->datatype != XMMS_OBJECT_CMD_ARG_INT32)
+	if (res->datatype != XMMS_OBJECT_CMD_ARG_INT32) {
 		return 0;
+	}
 
 	*r = res->data.inte;
 	
@@ -547,8 +547,9 @@
 		return 0;
 	}
 
-	if (res->datatype != XMMS_OBJECT_CMD_ARG_STRING)
+	if (res->datatype != XMMS_OBJECT_CMD_ARG_STRING) {
 		return 0;
+	}
 
 	*r = res->data.string;
 
@@ -725,23 +726,22 @@
 int
 xmmsc_result_dict_foreach (xmmsc_result_t *res, xmmsc_foreach_func func, void *user_data)
 {
-	xmmsc_foreach_t *fc;
+	xmmsc_foreach_t fc;
 
 	if (!res || res->error != XMMS_ERROR_NONE) {
 		return 0;
 	}
 
-	if (res->datatype != XMMS_OBJECT_CMD_ARG_DICT)
+	if (res->datatype != XMMS_OBJECT_CMD_ARG_DICT) {
 		return 0;
+	}
 
-	fc = x_new0 (xmmsc_foreach_t, 1);
-	fc->func = func;
-	fc->userdata = user_data;
+	memset(&fc, 0, sizeof(fc));
+	fc.func = func;
+	fc.userdata = user_data;
+
+	x_hash_foreach (res->data.hash, xmmsc_result_dict_foreach_cb, &fc);
 
-	x_hash_foreach (res->data.hash, xmmsc_result_dict_foreach_cb, fc);
-	
-	free (fc);
-	
 	return 1;
 }
 
@@ -777,8 +777,9 @@
 		return 0;
 	}
 
-	if (!res->islist)
+	if (!res->islist) {
 		return 0;
+	}
 
 	return !!res->current;
 }
@@ -796,22 +797,22 @@
 int
 xmmsc_result_list_next (xmmsc_result_t *res)
 {
-	xmmsc_result_value_t *val;
-
 	if (!res || res->error != XMMS_ERROR_NONE) {
 		return 0;
 	}
 
-	if (!res->islist)
+	if (!res->islist) {
 		return 0;
+	}
 
-	if (!res->current)
+	if (!res->current) {
 		return 0;
+	}
 
 	res->current = res->current->next;
 	
 	if (res->current) {
-		val = res->current->data;
+		xmmsc_result_value_t *val = res->current->data;
 		res->data.generic = val->value.generic;
 		res->datatype = val->type;
 	} else {
@@ -837,10 +838,11 @@
 
 	res->current = res->list;
 
-	if (res->current)
+	if (res->current) {
 		res->data.generic = res->current->data;
-	else
+	} else {
 		res->data.generic = NULL;
+	}
 
 	return 1;
 }
@@ -913,7 +915,10 @@
 {
 	xmmsc_result_t *res;
 
-	res = x_new0 (xmmsc_result_t, 1);
+	if (!(res = x_new0 (xmmsc_result_t, 1))) {
+		x_oom();
+		return NULL;
+	}
 
 	res->c = c;
 	xmmsc_ref (c);
@@ -938,10 +943,14 @@
 	xmmsc_result_value_t *val;
 	uint32_t len;
 
-	val = x_new0 (xmmsc_result_value_t, 1);
+	if (!(val = x_new0 (xmmsc_result_value_t, 1))) {
+		x_oom();
+		return NULL;
+	}
 
-	if (!xmms_ipc_msg_get_int32 (msg, (int32_t *)&val->type))
+	if (!xmms_ipc_msg_get_int32 (msg, (int32_t *)&val->type)) {
 		goto err;
+	}
 
 	switch (val->type) {
 		case XMMS_OBJECT_CMD_ARG_STRING:
@@ -961,8 +970,9 @@
 			break;
 		case XMMS_OBJECT_CMD_ARG_DICT:
 			val->value.dict = xmmsc_deserialize_hashtable (msg);
-			if (!val->value.dict)
+			if (!val->value.dict) {
 				goto err;
+			}
 			break;
 		case XMMS_OBJECT_CMD_ARG_NONE:
 			break;
@@ -989,19 +999,23 @@
 	x_hash_t *h;
 	char *key;
 
-	if (!xmms_ipc_msg_get_uint32 (msg, &entries))
+	if (!xmms_ipc_msg_get_uint32 (msg, &entries)) {
 		return NULL;
+	}
 
 	h = x_hash_new_full (x_str_hash, x_str_equal, free, xmmsc_result_value_free);
 
 	for (i = 1; i <= entries; i++) {
 		xmmsc_result_value_t *val;
 
-		if (!xmms_ipc_msg_get_string_alloc (msg, &key, &len))
+		if (!xmms_ipc_msg_get_string_alloc (msg, &key, &len)) {
 			goto err;
+		}
 
 		val = xmmsc_result_parse_value (msg);
-		if (!val) goto err;
+		if (!val) {
+			goto err;
+		}
 
 		x_hash_insert (h, key, val);
 	}
Only in xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient: result.c~
diff -ur xmms2.git-snapshot-200507282137-org/src/clients/lib/xmmsclient/xmmsclient.c xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient/xmmsclient.c
--- xmms2.git-snapshot-200507282137-org/src/clients/lib/xmmsclient/xmmsclient.c	2005-07-29 01:38:31.000000000 +0300
+++ xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient/xmmsclient.c	2005-07-29 02:07:30.000000000 +0300
@@ -99,8 +99,12 @@
 		return NULL;
 	}
 
+	if (!(c->clientname = strdup (clientname))) {
+		x_free(c);
+		return NULL;
+	}
+
 	xmmsc_ref (c);
-	c->clientname = strdup (clientname);
 	cmd_id = 0;
 
 	return c;
@@ -147,7 +151,7 @@
 	uint32_t i;
 	int ret;
 
-	char path[256];
+	char path[PATH_MAX];
 
 	x_api_error_if (!c, "with a NULL connection", false);
 
@@ -158,9 +162,9 @@
 		if (!pwd || !pwd->pw_name)
 			return false;
 
-		snprintf (path, 256, "unix:///tmp/xmms-ipc-%s", pwd->pw_name);
+		snprintf (path, sizeof(path), "unix:///tmp/xmms-ipc-%s", pwd->pw_name);
 	} else {
-		snprintf (path, 256, "%s", ipcpath);
+		snprintf (path, sizeof(path), "%s", ipcpath);
 	}
 
 	ipc = xmmsc_ipc_init ();
@@ -240,7 +244,7 @@
 	xmmsc_ipc_destroy (c->ipc);
 
 	free (c->clientname);
-	free(c);
+	free (c);
 }
 
 /**
@@ -294,7 +298,7 @@
 		return 0;
 	}
 
-	memset (target, '\0', len);
+	memset (target, 0, len);
 
 	pos = fmt;
 	while (strlen (target) + 1 < len) {
@@ -316,7 +320,7 @@
 			break;
 		}
 
-		memset (key, '\0', keylen + 1);
+		memset (key, 0, keylen + 1);
 		strncpy (key, next_key + 2, keylen);
 
 		if (strcmp (key, "seconds") == 0) {
@@ -328,7 +332,7 @@
 				strncat (target, "00", len - strlen (target) - 1);
 			} else {
 				char seconds[10];
-				snprintf (seconds, sizeof seconds, "%02d", (duration/1000)%60);
+				snprintf (seconds, sizeof(seconds), "%02d", (duration/1000)%60);
 				strncat (target, seconds, len - strlen (target) - 1);
 			}
 		} else if (strcmp (key, "minutes") == 0) {
@@ -340,7 +344,7 @@
 				strncat (target, "00", len - strlen (target) - 1);
 			} else {
 				char minutes[10];
-				snprintf (minutes, sizeof minutes, "%02d", duration/60000);
+				snprintf (minutes, sizeof(minutes), "%02d", duration/60000);
 				strncat (target, minutes, len - strlen (target) - 1);
 			}
 		} else {
Only in xmms2.git-snapshot-200507282137/src/clients/lib/xmmsclient: xmmsclient.c~
diff -ur xmms2.git-snapshot-200507282137-org/src/include/xmmsc/xmmsc_util.h xmms2.git-snapshot-200507282137/src/include/xmmsc/xmmsc_util.h
--- xmms2.git-snapshot-200507282137-org/src/include/xmmsc/xmmsc_util.h	2005-07-29 01:38:31.000000000 +0300
+++ xmms2.git-snapshot-200507282137/src/include/xmmsc/xmmsc_util.h	2005-07-29 02:39:25.000000000 +0300
@@ -8,6 +8,7 @@
 #define x_return_null_if_fail(expr) x_return_val_if_fail (expr, NULL)
 #define x_new0(type, num) calloc (1, sizeof (type) * num)
 #define x_malloc0(size) calloc (1, size)
+#define x_oom() do { fprintf(stderr, "Out of memory in " __FILE__ "on row %d\n", __LINE__); } while (0)
 
 #define XPOINTER_TO_INT(p)      ((int)   (p))
 #define XPOINTER_TO_UINT(p)     ((unsigned int)  (p))
Only in xmms2.git-snapshot-200507282137/src/include/xmmsc: xmmsc_util.h~

