Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random fixes 2 #1017

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion camlibs/ax203/ax203_decode_yuv_delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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!! */
Expand All @@ -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
Expand Down
24 changes: 8 additions & 16 deletions camlibs/canon/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion camlibs/pentax/pslr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion camlibs/ptp2/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion camlibs/ptp2/ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion camlibs/quicktake1x0/qtkn-decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion camlibs/st2205/st2205.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions camlibs/tp6801/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libgphoto2/gphoto2-camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion libgphoto2_port/usbdiskdirect/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion libgphoto2_port/usbscsi/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 3 additions & 7 deletions libgphoto2_port/vusb/vcamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Loading