diff --git a/camlibs/ptp2/library.c b/camlibs/ptp2/library.c index cf21a85f7..29ba9811e 100644 --- a/camlibs/ptp2/library.c +++ b/camlibs/ptp2/library.c @@ -133,7 +133,18 @@ translate_ptp_result (uint16_t result) case PTP_ERROR_IO: case PTP_ERROR_DATA_EXPECTED: case PTP_ERROR_RESP_EXPECTED: return GP_ERROR_IO; - default: return GP_ERROR; + default: { + /* If result is actually a GP_ERROR code (see gphoto2-port-result.h), then we simply pass it through as is. + * This works because those two value ranges have no overlap: + * - PTP errors are either 0x0..., 0x2.... or 0xA.... + * - GP errors (as uint16_t) are 0xF... + */ + int int_res = (int16_t)result; + if (-99 <= int_res && int_res <= 0) + return int_res; + else + return GP_ERROR; + } } } diff --git a/camlibs/ptp2/ptp.h b/camlibs/ptp2/ptp.h index 494f1da06..bff5a2e75 100644 --- a/camlibs/ptp2/ptp.h +++ b/camlibs/ptp2/ptp.h @@ -31,6 +31,8 @@ #include #endif #include "libgphoto2/gphoto2-endian.h" +#include +#include #include "device-flags.h" #ifdef __cplusplus @@ -102,8 +104,10 @@ static inline uint32_t _post_inc(uint32_t* o, int n) #define array_extend(ARRAY, LEN) do { \ (ARRAY)->val = realloc((ARRAY)->val, ((ARRAY)->len + (LEN)) * sizeof((ARRAY)->val[0])); \ - if (!(ARRAY)->val) \ - ptp_error(params, "PANIC: realloc failed"); \ + if (!(ARRAY)->val) { \ + GP_LOG_E ("Out of memory: 'realloc' of %ld bytes failed.", ((ARRAY)->len + (LEN)) * sizeof((ARRAY)->val[0])); \ + return GP_ERROR_NO_MEMORY; \ + } \ } while(0) #define array_push_back(ARRAY, VAL) do { \ diff --git a/libgphoto2_port/gphoto2/gphoto2-port-result.h b/libgphoto2_port/gphoto2/gphoto2-port-result.h index 319a73b1e..70c5bc819 100644 --- a/libgphoto2_port/gphoto2/gphoto2-port-result.h +++ b/libgphoto2_port/gphoto2/gphoto2-port-result.h @@ -40,6 +40,13 @@ * \brief Out of memory */ #define GP_ERROR_NO_MEMORY -3 +/* FIXME: GP_ERROR_NO_MEMORY is used to communicate two completely differnt + * things, which have nothing to do with each other: + * - the camera went out of memory because the storage space ran out, this + * is totally "normal" + * - a malloc on the host computer failed: this will completely interrupt + * the functionality and likely crash the process soonish + */ /** * \brief Error in the camera driver */