Skip to content

Commit 971197a

Browse files
committed
[atari] 4.5.2 removed all mallocs for atari, fuji_appkey buffer needs to be 2 bytes larger than key
1 parent 7a8a60b commit 971197a

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
## [4.5.2] - 2024-08-25
6+
7+
- [atari] fuji_read_appkey no longer uses malloc, but requires the data buffer passed in to be at least 2 bytes larger than the keysize to work.
8+
59
## [4.5.1] - 2024-08-24
610

711
- [atari] set dtimlo to 1 for appkey read, 2 for appkey write to reduce timeouts when reading / writing a new appkey

atari/src/fn_fuji/fuji_appkey_open_read.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ bool fuji_read_appkey(uint8_t key_id, uint16_t *count, uint8_t *data)
1818
uint8_t open_data[6];
1919
uint8_t mode = 0; // READ with standard 64 byte size
2020
uint16_t buffer_size = 64; // 64 is default, gets adjusted if mode is different
21-
uint8_t *buffer; // the malloc'd buffer to read into before copying to user's data buffer
2221
uint16_t bytes_read;
2322

2423
if (ak_creator_id == 0) {
@@ -31,9 +30,6 @@ bool fuji_read_appkey(uint8_t key_id, uint16_t *count, uint8_t *data)
3130
// buffer_size = 256;
3231
// }
3332

34-
buffer = malloc(buffer_size + 2); // 2 for length bytes
35-
if (!buffer) return false;
36-
3733
open_data[0] = ak_creator_id & 0xFF;
3834
open_data[1] = ak_creator_id >> 8;
3935
open_data[2] = ak_app_id;
@@ -45,27 +41,27 @@ bool fuji_read_appkey(uint8_t key_id, uint16_t *count, uint8_t *data)
4541
OS.dcb.dbuf = open_data;
4642
bus();
4743
if (!fuji_success()) {
48-
free(buffer);
4944
return false;
5045
}
5146

5247
copy_fuji_cmd_data(t_fuji_read_appkey);
53-
OS.dcb.dbuf = buffer;
48+
OS.dcb.dbuf = data;
5449
OS.dcb.dbyt = buffer_size + 2; // add 2 for count bytes
5550
OS.dcb.dtimlo = 1; // make timeout 1 second, as it's an SD read if it exists, if it's no there, we get a double timeout and we really don't want to wait forever
5651
bus();
5752
if (!fuji_success()) {
58-
free(buffer);
5953
return false;
6054
}
6155

62-
bytes_read = buffer[0] + (buffer[1] << 8);
56+
bytes_read = data[0] + (data[1] << 8);
6357
*count = bytes_read;
6458
if (bytes_read > 0) {
65-
// skip the first 2 bytes, copy buffer data to user's data
66-
memcpy(data, &buffer[2], bytes_read);
59+
// move the data from data+2 to data, and set everything else to 0 after this. the count is returned via parameter
60+
memmove(data, &data[2], bytes_read);
61+
if (bytes_read < buffer_size) {
62+
memset(&data[bytes_read], 0, buffer_size - bytes_read);
63+
}
6764
}
68-
free(buffer);
6965
return true;
7066

7167
}

fujinet-fuji.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,17 +500,17 @@ bool fuji_unmount_disk_image(uint8_t ds);
500500
bool fuji_unmount_host_slot(uint8_t hs);
501501

502502
/**
503-
* @brief Opens and reads from appkey using the provided details
504-
* @param key_id the specific key id of this application
505-
* @param count a pointer to an int for the number of bytes that were read
506-
* @param data a pointer to the memory to write the data back to.
503+
* @brief Opens and reads from appkey using the provided details. Writes to the data buffer, and sets count to the amount of data read if it is less than the full keysize.
504+
* @param key_id the specific key id of this application.
505+
* @param count a pointer to an int for the number of bytes that were read.
506+
* @param data a pointer to the memory to write the data back to. WARNING: The data buffer needs to be at least 2 more bytes larger than the keysize.
507507
* @return success status of the call. If either the initial OPEN or subsequent READ fail, will return false.
508508
*/
509509
bool fuji_read_appkey(uint8_t key_id, uint16_t *count, uint8_t *data);
510510

511511
/**
512-
* @brief Writes to an appkey using the provided details previously setup with fuji_set_appkey_details
513-
* @param key_id the specific key id of this application
512+
* @brief Writes to an appkey using the provided details previously setup with fuji_set_appkey_details.
513+
* @param key_id the specific key id of this application.
514514
* @param count the number of bytes in the buffer to write to the appkey.
515515
* @param data a pointer to the memory to write from.
516516
* @return success status of the call. If either the initial OPEN or subsequent WRITE fail, will return false.

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.5.1
1+
4.5.2

0 commit comments

Comments
 (0)