+2008-02-21 Helge Hess <helge.hess@opengroupware.org>
+
+ * FdExt.subproj/NSString+Escaping.m: fixed a free() bug introduced in
+ the unichar conversion of v4.7.197 (v4.7.200)
+
2008-02-21 Helge Hess <helge.hess@opengroupware.org>
* FdExt.subproj/NGPropertyListParser.m: fixed NSException not to use
// Unicode!
unichar *src;
unichar *buffer;
- int pos = 0;
+ int len, pos, srcIdx;
NSString *s;
- if ((pos = [self length]) == 0)
+ if ((len = [self length]) == 0)
return @"";
-
- src = malloc(sizeof(unichar) * (pos + 2));
+
+ src = malloc(sizeof(unichar) * (len + 2));
[self getCharacters:src];
- src[pos] = 0; // zero-terminate
+ src[len] = 0; // zero-terminate
- buffer = malloc(sizeof(unichar) * ((pos * 2) + 1));
+ buffer = malloc(sizeof(unichar) * ((len * 2) + 1));
- for (pos = 0; *src != 0; pos++, src++) {
- switch (*src) {
+ for (pos = 0, srcIdx = 0; srcIdx < len; pos++, srcIdx++) {
+ switch (src[srcIdx]) {
case '\n':
buffer[pos] = '\\'; pos++;
buffer[pos] = 'n';
break;
default:
- buffer[pos] = *src;
+ buffer[pos] = src[srcIdx];
break;
}
}
buffer[pos] = '\0';
s = [NSString stringWithCharacters:buffer length:pos];
- free(buffer); buffer = NULL;
- free(src); src = NULL;
+
+ if (buffer != NULL) { free(buffer); buffer = NULL; }
+ if (src != NULL) { free(src); src = NULL; }
return s;
}