Differences From Artifact [b556a211fc]:
- File
src/OFStream.m
— part of check-in
[b464ddcda5]
at
2009-06-09 13:21:12
on branch trunk
— Handle reads with a returned size of 0 safely in -[readLine].
Before, it could call memcpy with size of 0 on a pointer that might be
NULL and thus might be undefined behaviour. This way, it's compatible to
the OFSocket change in the commit before. (user: js, size: 4592) [annotate] [blame] [check-ins using]
To Artifact [fc7e1fba0a]:
- File src/OFStream.m — part of check-in [328decd247] at 2009-07-17 11:25:49 on branch trunk — Use +[stringWithCString:andLength:] in -[readLine]. (user: js, size: 4170) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
66 67 68 69 70 71 72 | OFString *ret; /* Look if there's a line or \0 in our cache */ if (cache != NULL) { for (i = 0; i < cache_len; i++) { if (OF_UNLIKELY(cache[i] == '\n' || cache[i] == '\0')) { | < | | < < | < < < < | < < < < < < < < < < < | < < < > | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | OFString *ret; /* Look if there's a line or \0 in our cache */ if (cache != NULL) { for (i = 0; i < cache_len; i++) { if (OF_UNLIKELY(cache[i] == '\n' || cache[i] == '\0')) { ret = [OFString stringWithCString: cache andLength: i]; tmp = [self allocMemoryWithSize: cache_len - i - 1]; memcpy(tmp, cache + i + 1, cache_len - i - 1); [self freeMemory: cache]; cache = tmp; cache_len -= i + 1; return ret; } } } /* Read until we get a newline or \0 */ tmp = [self allocMemoryWithSize: pagesize]; for (;;) { if ([self atEndOfStream]) { [self freeMemory: tmp]; if (cache == NULL) return nil; ret = [OFString stringWithCString: cache andLength: cache_len]; [self freeMemory: cache]; cache = NULL; cache_len = 0; return ret; } |
︙ | ︙ |