try to fix a bug Lorenz told me about
in fwrite
This commit is contained in:
2023-12-05 22:29:15 +01:00
parent 5fd8bb3044
commit a8537ba6d4
4 changed files with 24 additions and 6 deletions

View File

@@ -100,12 +100,12 @@ size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
* @return The number of bytes written
*/
size_t tftp_custom_fwrite(const void* buf, size_t bytes, tftp_custom_file_t* handle) {
if (handle->offset + bytes > handle->len) {
bytes = handle->len - handle->offset;
if (handle->offset + bytes >= handle->len) {
bytes = handle->len - handle->offset - 1;
}
memcpy(handle->data + handle->offset, buf, bytes);
handle->offset += bytes;
if (handle->offset > handle->len) {
if (handle->offset >= handle->len) {
bytes = 0;
}
return bytes;
@@ -171,7 +171,7 @@ void tftp_close(void* handle) {
if (handle == &virt_file[VIRT_TEXT_TXT]) {
lcd_clear_images();
lcd_clear_text();
lcd_display_text((const char*)virt_file[VIRT_TEXT_TXT].data, 0, 0, LCD_COLOR_WHITE, LCD_TRANSPARENT, LCD_FONT16);
lcd_display_text((char*)virt_file[VIRT_TEXT_TXT].data, 0, 0, LCD_COLOR_WHITE, LCD_TRANSPARENT, LCD_FONT16);
}
if (handle == &virt_file[VIRT_INDEX_TXT] || handle == &virt_file[VIRT_IMAGE_BMP]