From a050012bfd9aa41f7fa14fb9d013df721872192f Mon Sep 17 00:00:00 2001 From: Daniel C Date: Wed, 3 Jan 2024 20:25:50 -0500 Subject: [PATCH] Deprecate ptp_dup_uint_array Arrays will be returned as allocated for thread-safety --- src/lib.c | 9 --------- src/operations.c | 11 +++++++++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/lib.c b/src/lib.c index d93a178..0b293d5 100644 --- a/src/lib.c +++ b/src/lib.c @@ -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; @@ -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; diff --git a/src/operations.c b/src/operations.c index dd88a9e..d7a914e 100644 --- a/src/operations.c +++ b/src/operations.c @@ -9,6 +9,13 @@ #include #include +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)); @@ -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; } @@ -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; }