You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2013/09/20 08:23:08 UTC

svn commit: r1524908 - /incubator/celix/trunk/framework/private/src/manifest.c

Author: abroekhuis
Date: Fri Sep 20 06:23:08 2013
New Revision: 1524908

URL: http://svn.apache.org/r1524908
Log:
CELIX-76: Added string terminators to newly allocated string. Removed realloc usage which doesn't work in combination with apr_palloc. Note: Now the memory is increased by allocating a new block, but since the pool is destroyed shortly after usage I don't think this is a problem.

Modified:
    incubator/celix/trunk/framework/private/src/manifest.c

Modified: incubator/celix/trunk/framework/private/src/manifest.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/manifest.c?rev=1524908&r1=1524907&r2=1524908&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/manifest.c (original)
+++ incubator/celix/trunk/framework/private/src/manifest.c Fri Sep 20 06:23:08 2013
@@ -124,6 +124,7 @@ celix_status_t manifest_read(manifest_pt
 					(tolower(lbuf[2]) == 'm') && (tolower(lbuf[3]) == 'e') &&
 					(lbuf[4] == ':') && (lbuf[5] == ' ')) {
 					name = (char *) apr_palloc(subpool, (len + 1) - 6);
+					name[0] = '\0';
 					name = strncpy(name, lbuf+6, len - 6);
 					name[len - 6] = '\0';
 				} else {
@@ -134,6 +135,7 @@ celix_status_t manifest_read(manifest_pt
 				if (fpeek(file) == ' ') {
 					int newlen = len - 6;
 					lastline = (char *) apr_palloc(subpool, newlen + 1);
+					lastline[0] = '\0';
 					lastline = strncpy(lastline, lbuf+6, len - 6);
 					lastline[newlen] = '\0';
 					continue;
@@ -141,16 +143,20 @@ celix_status_t manifest_read(manifest_pt
 			} else {
 				int newlen = strlen(lastline) + len;
 				char * buf = (char *) apr_palloc(subpool, newlen);
+				buf[0] = '\0';
 				strcpy(buf, lastline);
 				strncat(buf, lbuf+1, len - 1);
 				buf[newlen] = '\0';
 
 				if (fpeek(file) == ' ') {
-					lastline = realloc(lastline, strlen(buf) + 1);
+//					lastline = realloc(lastline, strlen(buf) + 1);
+					lastline = (char *) apr_palloc(subpool, strlen(buf) + 1);
+					lastline[0] = '\0';
 					lastline = strcpy(lastline, buf);
 					continue;
 				}
 				name = (char *) apr_palloc(subpool, strlen(buf) + 1);
+				name[0] = '\0';
 				name = strcpy(name, buf);
 				name[strlen(buf)] = '\0';
 				lastline = NULL;
@@ -219,6 +225,7 @@ celix_status_t manifest_readAttributes(m
 		if (lbuf[0] == ' ') {
 			int newlen = strlen(lastLine) + len;
 			char * buf = (char *) apr_palloc(subpool, newlen);
+			buf[0] = '\0';
 
 			// Line continued
 			if (name == NULL) {
@@ -231,11 +238,14 @@ celix_status_t manifest_readAttributes(m
 			strncat(buf, lbuf+1, len - 1);
 
 			if (fpeek(file) == ' ') {
-				lastLine = realloc(lastLine, strlen(buf) + 1);
+//				lastLine = realloc(lastLine, strlen(buf) + 1);
+				lastLine = (char *) apr_palloc(subpool, strlen(buf) + 1);
+				lastLine[0] = '\0';
 				lastLine = strcpy(lastLine, buf);
 				continue;
 			}
 			value = (char *) apr_palloc(subpool, strlen(buf) + 1);
+			value[0] = '\0';
 			value = strcpy(value, buf);
 			lastLine = NULL;
 		} else {
@@ -250,16 +260,19 @@ celix_status_t manifest_readAttributes(m
 				return CELIX_FILE_IO_EXCEPTION;
 			}
 			name = (char *) apr_palloc(subpool, (i + 1) - 2);
+			name[0] = '\0';
 			name = strncpy(name, lbuf, i - 2);
 			name[i - 2] = '\0';
 			if (fpeek(file) == ' ') {
 				int newlen = len - i;
 				lastLine = (char *) apr_palloc(subpool, newlen + 1);
+				lastLine[0] = '\0';
 				lastLine = strncpy(lastLine, lbuf+i, len -i);
 				lastLine[newlen] = '\0';
 				continue;
 			}
 			value = (char *) apr_palloc(subpool, (len + 1) - i);
+			value[0] = '\0';
 			value = strncpy(value, lbuf+i, len - i);
 			value[len - i] = '\0';
 		}