Index: src/OFHashes.m ================================================================== --- src/OFHashes.m +++ src/OFHashes.m @@ -432,11 +432,11 @@ - (OFString*)md5Hash { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *hash = [OFMD5Hash md5Hash]; uint8_t *digest; - char ret_c[33]; + char ret_c[32]; size_t i; [hash updateWithBuffer: string ofSize: length]; digest = [hash digest]; @@ -448,23 +448,23 @@ low = digest[i] & 0x0F; ret_c[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); ret_c[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } - ret_c[32] = 0; [pool release]; - return [OFString stringWithCString: ret_c]; + return [OFString stringWithCString: ret_c + length: 32]; } - (OFString*)sha1Hash { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *hash = [OFSHA1Hash sha1Hash]; uint8_t *digest; - char ret_c[41]; + char ret_c[40]; size_t i; [hash updateWithBuffer: string ofSize: length]; digest = [hash digest]; @@ -476,12 +476,12 @@ low = digest[i] & 0x0F; ret_c[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); ret_c[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } - ret_c[40] = 0; [pool release]; - return [OFString stringWithCString: ret_c]; + return [OFString stringWithCString: ret_c + length: 40]; } @end Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -128,20 +128,18 @@ /* Look if there's a newline or \0 */ for (i = 0; i < len; i++) { if (OF_UNLIKELY(tmp[i] == '\n' || tmp[i] == '\0')) { @try { ret_c = [self - allocMemoryWithSize: cache_len + - i + 1]; + allocMemoryWithSize: cache_len + i]; } @catch (OFException *e) { [self freeMemory: tmp]; @throw e; } if (cache != NULL) memcpy(ret_c, cache, cache_len); memcpy(ret_c + cache_len, tmp, i); - ret_c[cache_len + i] = '\0'; if (i < len) { @try { tmp2 = [self allocMemoryWithSize: len - @@ -166,11 +164,12 @@ [self freeMemory: tmp]; @try { ret = [OFString stringWithCString: ret_c - encoding: encoding]; + encoding: encoding + length: cache_len + i]; } @finally { [self freeMemory: ret_c]; } return ret; } Index: src/OFURLEncoding.m ================================================================== --- src/OFURLEncoding.m +++ src/OFURLEncoding.m @@ -53,14 +53,14 @@ ret_c[i++] = '%'; ret_c[i++] = (high > 9 ? high - 10 + 'A' : high + '0'); ret_c[i++] = (low > 9 ? low - 10 + 'A' : low + '0'); } } - ret_c[i] = '\0'; @try { - ret = [OFString stringWithCString: ret_c]; + ret = [OFString stringWithCString: ret_c + length: i]; } @finally { free(ret_c); } return ret; @@ -123,9 +123,8 @@ @try { ret = [OFString stringWithCString: ret_c]; } @finally { free(ret_c); } - return ret; } @end Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -124,11 +124,11 @@ char *str_c; size_t len, i, j, attrs_count; OFXMLAttribute **attrs_carray; OFString *ret, *tmp; - len = [name cStringLength] + 4; + len = [name cStringLength] + 3; str_c = [self allocMemoryWithSize: len]; /* Start of tag */ *str_c = '<'; memcpy(str_c + 1, [name cString], [name cStringLength]); @@ -202,21 +202,20 @@ i += [name cStringLength]; } else str_c[i++] = '/'; str_c[i++] = '>'; - str_c[i++] = '\0'; assert(i == len); [pool release]; @try { - ret = [OFString stringWithCString: str_c]; + ret = [OFString stringWithCString: str_c + length: len]; } @finally { [self freeMemory: str_c]; } - return ret; } - addAttribute: (OFXMLAttribute*)attr { @@ -278,16 +277,16 @@ size_t len, append_len; size_t i, j; OFString *ret; j = 0; - len = length + 1; + len = length; /* * We can't use allocMemoryWithSize: here as it might be a @"" literal */ - if ((str_c = malloc(len + 1)) == NULL) + if ((str_c = malloc(len)) == NULL) @throw [OFOutOfMemoryException newWithClass: isa size: len]; for (i = 0; i < length; i++) { switch (string[i]) { @@ -330,17 +329,16 @@ j += append_len; } else str_c[j++] = string[i]; } - str_c[j++] = '\0'; assert(j == len); @try { - ret = [OFString stringWithCString: str_c]; + ret = [OFString stringWithCString: str_c + length: len]; } @finally { free(str_c); } - return ret; } @end