From 3f5b90681531cada2f1f3253f97b7adbceab1b68 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Thu, 5 Feb 2015 07:21:01 +0000 Subject: replaced some exit(1) by error returns https://sourceforge.net/p/gphoto/bugs/1007/ git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@15350 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/canon/crc.c | 6 +++--- camlibs/canon/crc.h | 2 +- camlibs/canon/serial.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'camlibs/canon') diff --git a/camlibs/canon/crc.c b/camlibs/canon/crc.c index 5f44db07f..17b8990da 100644 --- a/camlibs/canon/crc.c +++ b/camlibs/canon/crc.c @@ -223,7 +223,7 @@ find_init (int len) * program with a message to stderr. * */ -unsigned short +int canon_psa50_gen_crc (const unsigned char *pkt, int len) { int init; @@ -232,7 +232,7 @@ canon_psa50_gen_crc (const unsigned char *pkt, int len) if (init != -1) return chksum (init, len, pkt); fprintf (stderr, _("FATAL ERROR: initial CRC value for length %d unknown\n"), len); - exit (1); + return -1; } @@ -245,7 +245,7 @@ guess (const unsigned char *m, int len, int crc) if (chksum (i, len, m) == crc) return i; fprintf (stderr, _("unable to guess initial CRC value\n")); - exit (1); + return -1; } /** diff --git a/camlibs/canon/crc.h b/camlibs/canon/crc.h index c2bdd66ce..0e786ca8e 100644 --- a/camlibs/canon/crc.h +++ b/camlibs/canon/crc.h @@ -1,7 +1,7 @@ #ifndef CRC_H #define CRC_H -unsigned short canon_psa50_gen_crc(const unsigned char *pkt, int len); +int canon_psa50_gen_crc(const unsigned char *pkt, int len); int canon_psa50_chk_crc(const unsigned char *pkt, int len, unsigned short crc); #endif diff --git a/camlibs/canon/serial.c b/camlibs/canon/serial.c index de99a9a45..0c8568050 100644 --- a/camlibs/canon/serial.c +++ b/camlibs/canon/serial.c @@ -388,6 +388,8 @@ canon_serial_send_packet (Camera *camera, unsigned char type, unsigned char seq, if (type == PKT_EOT || type == PKT_ACK || type == PKT_NACK) len = 2; /* @@@ hack */ crc = canon_psa50_gen_crc (hdr, len + PKT_HDR_LEN); + if (crc == -1) + return GP_ERROR; pkt[len] = crc & 0xff; pkt[len + 1] = crc >> 8; @@ -720,10 +722,8 @@ canon_serial_recv_msg (Camera *camera, unsigned char mtype, unsigned char dir, u if (msg_pos + len > msg_size || !msg) { msg_size *= 2; msg = realloc (msg, msg_size); - if (!msg) { - perror ("realloc"); - exit (1); - } + if (!msg) + return NULL; } memcpy (msg + msg_pos, frag, len); msg_pos += len; -- cgit v1.2.1