Fix some sizes

This commit is contained in:
Flössie
2020-09-15 17:12:03 +02:00
parent 79278875da
commit 4d931ed9f4
3 changed files with 11 additions and 8 deletions

View File

@@ -373,9 +373,9 @@ format_message (j_common_ptr cinfo, char * buffer)
/* Format the message into the passed buffer */
if (isstring) {
snprintf(buffer, sizeof(buffer), msgtext, err->msg_parm.s);
snprintf(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
} else
snprintf(buffer, sizeof(buffer), msgtext,
snprintf(buffer, JMSG_LENGTH_MAX, msgtext,
err->msg_parm.i[0], err->msg_parm.i[1],
err->msg_parm.i[2], err->msg_parm.i[3],
err->msg_parm.i[4], err->msg_parm.i[5],

View File

@@ -97,6 +97,7 @@ static FILE* _printSetupTxt(
const char *fname, /* Input: filename, or NULL for stderr */
const char *fmt, /* Input: format (e.g., %5.1f or %3d) */
char *format, /* Output: format (e.g., (%5.1f,%5.1f)=%3d) */
std::size_t format_size,
char *type) /* Output: either 'f' or 'd', based on input format */
{
FILE *fp;
@@ -124,7 +125,7 @@ static FILE* _printSetupTxt(
}
/* Construct feature format */
snprintf(format, sizeof(format), "(%s,%s)=%%%dd ", fmt, fmt, val_width);
snprintf(format, format_size, "(%s,%s)=%%%dd ", fmt, fmt, val_width);
return fp;
}
@@ -358,7 +359,7 @@ void KLTWriteFeatureList(
}
if (fmt != nullptr) { /* text file or stderr */
fp = _printSetupTxt(fname, fmt, format, &type);
fp = _printSetupTxt(fname, fmt, format, sizeof(format), &type);
_printHeader(fp, format, FEATURE_LIST, 0, fl->nFeatures);
for (i = 0 ; i < fl->nFeatures ; i++) {
@@ -396,7 +397,7 @@ void KLTWriteFeatureHistory(
}
if (fmt != nullptr) { /* text file or stderr */
fp = _printSetupTxt(fname, fmt, format, &type);
fp = _printSetupTxt(fname, fmt, format, sizeof(format), &type);
_printHeader(fp, format, FEATURE_HISTORY, fh->nFrames, 0);
for (i = 0 ; i < fh->nFrames ; i++) {
@@ -435,7 +436,7 @@ void KLTWriteFeatureTable(
}
if (fmt != nullptr) { /* text file or stderr */
fp = _printSetupTxt(fname, fmt, format, &type);
fp = _printSetupTxt(fname, fmt, format, sizeof(format), &type);
_printHeader(fp, format, FEATURE_TABLE, ft->nFrames, ft->nFeatures);
for (j = 0 ; j < ft->nFeatures ; j++) {

View File

@@ -1046,8 +1046,10 @@ DCraw::dcraw_coeff_overrides(const char make[], const char model[], const int is
}
}
char name[strlen(make) + strlen(model) + 32];
snprintf(name, sizeof(name), "%s %s", make, model);
const std::size_t name_size = strlen(make) + strlen(model) + 32;
char name[name_size];
snprintf(name, name_size, "%s %s", make, model);
for (size_t i = 0; i < sizeof table / sizeof(table[0]); i++) {
if (strcasecmp(name, table[i].prefix) == 0) {