tftp
try to fix a bug Lorenz told me about in fread
This commit is contained in:
@@ -78,8 +78,8 @@ void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence) {
|
|||||||
* @param[in,out] handle Custom file handles
|
* @param[in,out] handle Custom file handles
|
||||||
*/
|
*/
|
||||||
size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
|
size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
|
||||||
if (handle->offset + bytes > handle->len) {
|
if (handle->offset + bytes >= handle->len) {
|
||||||
bytes = handle->len - handle->offset;
|
bytes = handle->len - handle->offset - 1;
|
||||||
}
|
}
|
||||||
memcpy(buf, handle->data + handle->offset, bytes);
|
memcpy(buf, handle->data + handle->offset, bytes);
|
||||||
handle->offset += bytes;
|
handle->offset += bytes;
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ TEST(TFTP, custom_fwrite) {
|
|||||||
write_file.len = 0;
|
write_file.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TFTP, custom_fread_fwrite_suggested_by_Lorentz) {
|
TEST(TFTP, custom_fread_fwrite_suggested_by_Lorenz) {
|
||||||
write_file.data = (char*)malloc(21 * sizeof(char));
|
write_file.data = (char*)malloc(21 * sizeof(char));
|
||||||
write_file.len = 21;
|
write_file.len = 21;
|
||||||
write_file.offset = 0;
|
write_file.offset = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user