diff --git a/camlibs/ax203/ax203_decode_yuv_delta.c b/camlibs/ax203/ax203_decode_yuv_delta.c index 1006b54f4c..43779cef61 100644 --- a/camlibs/ax203/ax203_decode_yuv_delta.c +++ b/camlibs/ax203/ax203_decode_yuv_delta.c @@ -43,6 +43,7 @@ #define CLAMP_U8(x) (((x) > 255) ? 255 : (((x) < 0) ? 0 : (x))) +#ifdef HAVE_LIBGD static const int corr_tables[4][8] = { /* Table 0 depends on wrap around to get negative corrections!! */ @@ -52,7 +53,6 @@ static const int corr_tables[4][8] = { { 0, 4, 8, 12, -16, -12, -8, -4 }, }; -#ifdef HAVE_LIBGD /* With in a compressed 4x4 block, the data is stored 4 component values at a time, compressed into 2 bytes, the first 5 bits are a starting value, then 2 bits encoding which correction/delta table to use and diff --git a/camlibs/canon/library.c b/camlibs/canon/library.c index dc89b49963..02fe91e7b7 100644 --- a/camlibs/canon/library.c +++ b/camlibs/canon/library.c @@ -2419,19 +2419,15 @@ make_dir_func (CameraFilesystem __unused__ *fs, const char *folder, if (strlen (folder) > 1) { /* folder is something more than / */ - if (strlen (folder) + 1 + strlen (name) > sizeof (gppath) - 1) { - GP_DEBUG ("make_dir_func: Arguments too long"); + if (snprintf (gppath, sizeof(gppath), "%s/%s", folder, name) >= (int)sizeof(gppath)) { + GP_LOG_E ("Arguments too long"); return GP_ERROR_BAD_PARAMETERS; } - - snprintf (gppath, sizeof(gppath), "%s/%s", folder, name); } else { - if (1 + strlen (name) > sizeof (gppath) - 1) { - GP_DEBUG ("make_dir_func: Arguments too long"); + if (snprintf (gppath, sizeof(gppath), "/%s", name) >= (int)sizeof(gppath)) { + GP_LOG_E ("Arguments too long"); return GP_ERROR_BAD_PARAMETERS; } - - snprintf (gppath, sizeof(gppath), "/%s", name); } canonpath = gphoto2canonpath (camera, gppath, context); @@ -2461,19 +2457,15 @@ remove_dir_func (CameraFilesystem __unused__ *fs, const char *folder, if (strlen (folder) > 1) { /* folder is something more than / */ - if (strlen (folder) + 1 + strlen (name) > sizeof (gppath) - 1) { - GP_DEBUG ("make_dir_func: Arguments too long"); + if (snprintf (gppath, sizeof(gppath), "%s/%s", folder, name) >= (int)sizeof(gppath)) { + GP_LOG_E ("Arguments too long"); return GP_ERROR_BAD_PARAMETERS; } - - snprintf (gppath, sizeof(gppath), "%s/%s", folder, name); } else { - if (1 + strlen (name) > sizeof (gppath) - 1) { - GP_DEBUG ("make_dir_func: Arguments too long"); + if (snprintf (gppath, sizeof(gppath), "/%s", name) >= (int)sizeof(gppath)) { + GP_LOG_E ("Arguments too long"); return GP_ERROR_BAD_PARAMETERS; } - - snprintf (gppath, sizeof(gppath), "/%s", name); } canonpath = gphoto2canonpath (camera, gppath, context); diff --git a/camlibs/pentax/pslr.c b/camlibs/pentax/pslr.c index 8e072251eb..f2b39583ff 100644 --- a/camlibs/pentax/pslr.c +++ b/camlibs/pentax/pslr.c @@ -982,7 +982,7 @@ int pslr_set_exposure_mode(pslr_handle_t h, pslr_exposure_mode_t mode) { } if ( p->model->need_exposure_mode_conversion ) { - mode = exposure_mode_conversion( mode ); + mode = (pslr_exposure_mode_t)exposure_mode_conversion( mode ); } return ipslr_handle_command_x18( p, true, X18_EXPOSURE_MODE, 2, 1, mode, 0); diff --git a/camlibs/ptp2/library.c b/camlibs/ptp2/library.c index c21779a4d8..519fce52bf 100644 --- a/camlibs/ptp2/library.c +++ b/camlibs/ptp2/library.c @@ -5653,7 +5653,8 @@ camera_sigma_fp_capture (Camera *camera, CameraCaptureType type, CameraFilePath C_PTP_REP (ptp_sigma_fp_clearimagedbsingle(params, captstatus.imageid)); - snprintf (path->name, sizeof(path->name), "%s%s", pictfileinfoex2.name, pictfileinfoex2.fileext); + if (snprintf (path->name, sizeof(path->name), "%s%s", pictfileinfoex2.name, pictfileinfoex2.fileext) >= (int)sizeof(path->name)) + GP_LOG_E("pictfileinfoex2.name and .fileext did not fit into path->name"); strcpy (path->folder,"/"); ret = gp_file_new (&file); diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c index d732aed8df..7b4d94d90a 100644 --- a/camlibs/ptp2/ptp.c +++ b/camlibs/ptp2/ptp.c @@ -412,7 +412,7 @@ fd_putfunc(PTPParams* params, void* private, PTPFDHandlerPrivate* priv = (PTPFDHandlerPrivate*)private; written = write (priv->fd, data, sendlen); - if (written != sendlen) + if ((unsigned long)written != sendlen) return PTP_ERROR_IO; return PTP_RC_OK; } diff --git a/camlibs/quicktake1x0/qtkn-decoder.c b/camlibs/quicktake1x0/qtkn-decoder.c index fe7f98406a..1512a96e36 100644 --- a/camlibs/quicktake1x0/qtkn-decoder.c +++ b/camlibs/quicktake1x0/qtkn-decoder.c @@ -112,7 +112,7 @@ int qtkn_decode(unsigned char *raw, int width, int height, unsigned char **out) for (c=0; c < 3; c++) { val = ((0x1000000/last[c] + 0x7ff) >> 12) * mul[c]; s = val > 65564 ? 10:12; - x = ~(-1 << (s-1)); + x = ~((unsigned int)-1 << (s-1)); val <<= 12-s; for (i=0; i < (int)(sizeof(buf[0])/sizeof(short)); i++) { ((short *)buf[c])[i] = (((short *)buf[c])[i] * val + x) >> s; diff --git a/camlibs/st2205/st2205.h b/camlibs/st2205/st2205.h index 1ef322536f..6ea4c11d2e 100644 --- a/camlibs/st2205/st2205.h +++ b/camlibs/st2205/st2205.h @@ -68,7 +68,8 @@ enum { all unique and don't change when files with the same name (after converting to ascii and truncating) are added / deleted. */ #define ST2205_SET_FILENAME(dest, name, idx) \ - snprintf(dest, sizeof(st2205_filename), "%04d-%s.png", (idx) + 1, name) + if (snprintf(dest, sizeof(st2205_filename), "%04d-%s.png", (idx) + 1, name) >= (int)sizeof(st2205_filename)) \ + GP_LOG_E ("extended st2205_filename did not fit into dest") struct st2205_coord { uint16_t x; diff --git a/camlibs/tp6801/library.c b/camlibs/tp6801/library.c index 69e1024232..0f66eb2c6b 100644 --- a/camlibs/tp6801/library.c +++ b/camlibs/tp6801/library.c @@ -151,9 +151,9 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, GPContext *context) { Camera *camera = data; - int idx, size; + int idx; #ifdef HAVE_LIBGD - int ret; + int ret, size; gdImagePtr im; void *gdpng; #endif diff --git a/libgphoto2/gphoto2-camera.c b/libgphoto2/gphoto2-camera.c index bc0eb4f2d9..8e8c728772 100644 --- a/libgphoto2/gphoto2-camera.c +++ b/libgphoto2/gphoto2-camera.c @@ -1014,7 +1014,7 @@ _get_widget_names (CameraWidget *widget, CameraList *list) case GP_WIDGET_MENU: case GP_WIDGET_RADIO: case GP_WIDGET_TEXT: - GP_WIDGET_RANGE: + case GP_WIDGET_RANGE: case GP_WIDGET_TOGGLE: case GP_WIDGET_DATE: { const char *name; diff --git a/libgphoto2_port/usbdiskdirect/linux.c b/libgphoto2_port/usbdiskdirect/linux.c index 1c37fdf51b..6428a51fae 100644 --- a/libgphoto2_port/usbdiskdirect/linux.c +++ b/libgphoto2_port/usbdiskdirect/linux.c @@ -146,7 +146,8 @@ gp_port_usbdiskdirect_resolve_symlink (const char *link) } else { *slash = 0; len = strlen (path); - snprintf (path + len, sizeof (path) - len, "/%s", buf); + if (snprintf (path + len, sizeof (path) - len, "/%s", buf) >= (int)sizeof (path) - len) + return NULL; } if (stat (path, &st)) diff --git a/libgphoto2_port/usbscsi/linux.c b/libgphoto2_port/usbscsi/linux.c index 7667127bba..344f055ca7 100644 --- a/libgphoto2_port/usbscsi/linux.c +++ b/libgphoto2_port/usbscsi/linux.c @@ -141,7 +141,8 @@ gp_port_usbscsi_resolve_symlink (const char *link) } else { *slash = 0; len = strlen (path); - snprintf (path + len, sizeof (path) - len, "/%s", buf); + if (snprintf (path + len, sizeof (path) - len, "/%s", buf) >= (int)sizeof (path) - len) + return NULL; } if (stat (path, &st)) diff --git a/libgphoto2_port/vusb/vcamera.c b/libgphoto2_port/vusb/vcamera.c index 86b8659dd4..f7c77fb188 100644 --- a/libgphoto2_port/vusb/vcamera.c +++ b/libgphoto2_port/vusb/vcamera.c @@ -1746,16 +1746,14 @@ static int ptp_datetime_getdesc (vcamera* cam, PTPDevicePropDesc *desc) { struct tm *tm; time_t xtime; - char xdate[40]; desc->DevicePropertyCode = 0x5011; desc->DataType = 0xffff; /* string */ desc->GetSet = 1; /* get only */ time(&xtime); tm = gmtime(&xtime); - sprintf(xdate,"%04d%02d%02dT%02d%02d%02d",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec); - desc->FactoryDefaultValue.str = strdup (xdate); - desc->CurrentValue.str = strdup (xdate); + desc->FactoryDefaultValue.str = aprintf("%04d%02d%02dT%02d%02d%02d",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec); + desc->CurrentValue.str = strdup (desc->FactoryDefaultValue.str); desc->FormFlag = 0; /* no form */ /*ptp_inject_interrupt (cam, 1000, 0x4006, 1, 0x5011, 0xffffffff);*/ return 1; @@ -1765,12 +1763,10 @@ static int ptp_datetime_getvalue (vcamera* cam, PTPPropertyValue *val) { struct tm *tm; time_t xtime; - char xdate[40]; time(&xtime); tm = gmtime(&xtime); - sprintf(xdate,"%04d%02d%02dT%02d%02d%02d",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec); - val->str = strdup (xdate); + val->str = aprintf("%04d%02d%02dT%02d%02d%02d",tm->tm_year + 1900,tm->tm_mon + 1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec); /*ptp_inject_interrupt (cam, 1000, 0x4006, 1, 0x5011, 0xffffffff);*/ return 1; }