[icinga-checkins] icinga.org: icinga-core/mfriedrich/ido: core: implement proper fix for #2913

git at icinga.org git at icinga.org
Wed Oct 3 01:14:51 CEST 2012


Module: icinga-core
Branch: mfriedrich/ido
Commit: 8ae0b453108acbe88c3ee363feb53e180b1590d8
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=8ae0b453108acbe88c3ee363feb53e180b1590d8

Author: Michael Friedrich <michael.friedrich at gmail.com>
Date:   Tue Sep 11 13:44:21 2012 +0200

core: implement proper fix for #2913

refs #2913

---

 common/macros.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/common/macros.c b/common/macros.c
index 7c37581..29c0737 100644
--- a/common/macros.c
+++ b/common/macros.c
@@ -1973,18 +1973,18 @@ int grab_standard_hostgroup_macro_r(icinga_macros *mac, int macro_type, hostgrou
 		}
 
 		/* if there no hostgroups members, we need to malloc at least an empty string for future calls of this function */
-		if (temp_len <= 0)
-			temp_len = 1;
+		if (!temp_len) {
+			*output = calloc(1, 1);
+			return OK;
+		}
 
 		/* allocate or reallocate the memory buffer */
 		if (*output == NULL) {
 			*output = (char *)malloc(temp_len);
-			(*output)[temp_len-1] = '\0';
 		} else {
 			init_len = strlen(*output);
 			temp_len += init_len;
 			*output = (char *)realloc(*output, temp_len);
-			(*output)[temp_len-1] = '\0';
 		}
 		/* now fill in the string with the member names */
 		for (temp_hostsmember = temp_hostgroup->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
@@ -2314,19 +2314,19 @@ int grab_standard_servicegroup_macro_r(icinga_macros *mac, int macro_type, servi
 			}
 		}
 
-		/* if there no hostgroups members, we need to malloc at least an empty string for future calls of this function */
-		if (temp_len <= 0)
-			temp_len = 1;
+		/* if there no servicegroups members, we need to malloc at least an empty string for future calls of this function */
+		if (!temp_len) {
+			*output = calloc(1, 1);
+			return OK;
+		}
 
 		/* allocate or reallocate the memory buffer */
 		if (*output == NULL) {
 			*output = (char *)malloc(temp_len);
-			(*output)[temp_len-1] = '\0';
 		} else {
 			init_len = strlen(*output);
 			temp_len += init_len;
 			*output = (char *)realloc(*output, temp_len);
-			(*output)[temp_len-1] = '\0';
 		}
 		/* now fill in the string with the group members */
 		for (temp_servicesmember = temp_servicegroup->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {





More information about the icinga-checkins mailing list