Overview
Comment: | Returning newly allocated buffers on reading is a bad idea. The programmer might forget that some of the data is arbitrary because there was less data than he requested which might lead to serious problems. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
09e6b3fc7bddde57e9c18cd44c105fbb |
User & Date: | js on 2009-04-07 15:44:54 |
Other Links: | manifest | tags |
Context
2009-04-08
| ||
13:13 | Throw an OFNotConnected exception when there was a clean disconnect. check-in: 69e41c48ff user: js tags: trunk | |
2009-04-07
| ||
15:44 |
Returning newly allocated buffers on reading is a bad idea. The programmer might forget that some of the data is arbitrary because there was less data than he requested which might lead to serious problems. check-in: 09e6b3fc7b user: js tags: trunk | |
2009-04-04
| ||
19:56 | Fix wrong documentation. check-in: a72c435267 user: js tags: trunk | |
Changes
Modified src/OFFile.h from [83b21b531b] to [8001780b38].
︙ | ︙ | |||
123 124 125 126 127 128 129 | * The buffer MUST be at least size * nitems big! * \return The number of bytes read */ - (size_t)readNItems: (size_t)nitems ofSize: (size_t)size intoBuffer: (uint8_t*)buf; | < < < < < < < < < < < | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | * The buffer MUST be at least size * nitems big! * \return The number of bytes read */ - (size_t)readNItems: (size_t)nitems ofSize: (size_t)size intoBuffer: (uint8_t*)buf; /** * Writes from a buffer into the file. * * \param buf The buffer from which the data is written to the file * \param size The size of the data that should be written * \param nitem The number of items to write * \return The number of bytes written */ - (size_t)writeNItems: (size_t)nitems ofSize: (size_t)size fromBuffer: (const uint8_t*)buf; @end |
Modified src/OFFile.m from [68e15040b2] to [2951d584dc].
︙ | ︙ | |||
124 125 126 127 128 129 130 | intoBuffer: (uint8_t*)buf { return [self readNItems: size ofSize: 1 intoBuffer: buf]; } | < < < < < < < < < < < < < < < < < < < < < < < < < < | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | intoBuffer: (uint8_t*)buf { return [self readNItems: size ofSize: 1 intoBuffer: buf]; } - (size_t)writeNItems: (size_t)nitems ofSize: (size_t)size fromBuffer: (const uint8_t*)buf { size_t ret; if ((ret = fwrite(buf, size, nitems, fp)) == 0 && |
︙ | ︙ |
Modified src/OFStream.h from [ae18f564f1] to [ed38ea4d16].
︙ | ︙ | |||
20 21 22 23 24 25 26 | * \param size The size of the data that should be read. * The buffer MUST be at least size big! * \return The number of bytes read */ - (size_t)readNBytes: (size_t)size intoBuffer: (uint8_t*)buf; | < < < < < < < < < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * \param size The size of the data that should be read. * The buffer MUST be at least size big! * \return The number of bytes read */ - (size_t)readNBytes: (size_t)size intoBuffer: (uint8_t*)buf; /** * Writes from a buffer into the stream. * * \param buf The buffer from which the data is written to the stream * \param size The size of the data that should be written * \return The number of bytes written */ |
︙ | ︙ |
Modified src/OFTCPSocket.m from [efdb457766] to [3dac29634e].
︙ | ︙ | |||
231 232 233 234 235 236 237 | @throw [OFNotConnectedException newWithClass: [self class]]; if ((ret = recv(sock, (char*)buf, size, 0)) < 1) @throw [OFReadFailedException newWithClass: [self class] andSize: size]; /* This is safe, as we already checked < 1 */ | < < < < < < < < < < < < < < < < < < < < | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | @throw [OFNotConnectedException newWithClass: [self class]]; if ((ret = recv(sock, (char*)buf, size, 0)) < 1) @throw [OFReadFailedException newWithClass: [self class] andSize: size]; /* This is safe, as we already checked < 1 */ return ret; } - (size_t)writeNBytes: (size_t)size fromBuffer: (const uint8_t*)buf { ssize_t ret; |
︙ | ︙ |