From 5c6c9e09432e4f0e4cc38cd0f609ef7e080e6092 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Sun, 28 Apr 2019 09:19:31 +0200 Subject: [PATCH] avoid division by zero (AFL) --- camlibs/pccam600/pccam600.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/camlibs/pccam600/pccam600.c b/camlibs/pccam600/pccam600.c index 15b8eb7ba..48d955b22 100644 --- a/camlibs/pccam600/pccam600.c +++ b/camlibs/pccam600/pccam600.c @@ -207,11 +207,16 @@ int pccam600_init(GPPort *port, GPContext *context){ gp_port_set_timeout(port,200000); CHECK(gp_port_usb_msg_read(port,0x08,0x00,0x1000,(char*)response,0x4)); nr_of_blocks = response[2]*256+response[1]; + + if (nr_of_blocks == 0) { + gp_context_error(context,_("pccam600_init: Expected %d blocks got %d"),64,nr_of_blocks); + return GP_ERROR; + } + nr_of_blocks = 512 / nr_of_blocks; gp_log(GP_LOG_DEBUG,"pccam600 library: init","nr_of_blocks %d",nr_of_blocks); - if (nr_of_blocks == 0){ - gp_context_error(context,_("pccam600_init: Expected %d blocks got %d"), - 64,nr_of_blocks); + if (nr_of_blocks == 0) { + gp_context_error(context,_("pccam600_init: Expected %d blocks got %d"),64,nr_of_blocks); return GP_ERROR; } gp_port_set_timeout(port,500);