Skip to content

Commit

Permalink
Deprecate ptp_dup_uint_array
Browse files Browse the repository at this point in the history
Arrays will be returned as allocated for thread-safety
  • Loading branch information
petabyt committed Jan 4, 2024
1 parent 6886709 commit a050012
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 0 additions & 9 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ void ptpusb_free_device_list(struct PtpDeviceEntry *e) {
}

int ptp_buffer_resize(struct PtpRuntime *r, size_t size) {
// TODO: Adjust this in a clever way
static int extra = 100;

ptp_verbose_log("Extending IO buffer to %X\n", size + extra);
r->data = realloc(r->data, size + extra);
r->data_length = size + extra;
Expand Down Expand Up @@ -244,13 +242,6 @@ void *ptp_dup_payload(struct PtpRuntime *r) {
return dup;
}

struct UintArray *ptp_dup_uint_array(struct UintArray *arr) {
struct UintArray *arr2 = malloc(4 + arr->length * 4);
if (arr2 == NULL) return NULL;
memcpy(arr2, arr, 4 + arr->length * 4);
return arr2;
}

int ptp_device_type(struct PtpRuntime *r) {
struct PtpDeviceInfo *di = r->di;
if (di == NULL) return PTP_DEV_EMPTY;
Expand Down
11 changes: 9 additions & 2 deletions src/operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
#include <camlib.h>
#include <ptp.h>

static struct UintArray *dup_uint_array(struct UintArray *arr) {
struct UintArray *dup = malloc(4 + arr->length * 4);
if (dup == NULL) return NULL;
memcpy(dup, arr, 4 + arr->length * 4);
return dup;
}

int ptpip_init_command_request(struct PtpRuntime *r, char *device_name) {
struct PtpIpInitPacket *p = (struct PtpIpInitPacket *)r->data;
memset(p, 0, sizeof(struct PtpIpInitPacket));
Expand Down Expand Up @@ -137,7 +144,7 @@ int ptp_get_storage_ids(struct PtpRuntime *r, struct UintArray **a) {

int rc = ptp_send(r, &cmd);

(*a) = ptp_dup_uint_array((void *)ptp_get_payload(r));
(*a) = dup_uint_array((void *)ptp_get_payload(r));

return rc;
}
Expand Down Expand Up @@ -206,7 +213,7 @@ int ptp_get_object_handles(struct PtpRuntime *r, int id, int format, int in, str

int rc = ptp_send(r, &cmd);

(*a) = ptp_dup_uint_array((void *)ptp_get_payload(r));
(*a) = dup_uint_array((void *)ptp_get_payload(r));

return rc;
}
Expand Down

0 comments on commit a050012

Please sign in to comment.