cppcheck: fix reports

[backend/bmp.c:133]: (error) Memory leak: bitmap
[backend/bmp.c:126]: (error) Memory leak: bitmap
[backend/composite.c:464]: (error) Array index -1 is out of bounds.
[backend/composite.c:507]: (error) Array index -1 is out of bounds.
[backend/dmatrix.c:962]: (style) Redundant condition: i!=0. 'i==0 || (i!=0 && binary[i-1]!='b')' is equivalent to 'i==0 || binary[i-1]!='b''
[backend/raster.c:122]: (error) Memory leak: rotated_pixbuf
[backend/raster.c:506]: (error) Memory leak: pixelbuf
[frontend/main.c:273]: (error) Uninitialized variable: format_string
[frontend_qt/exportwindow.cpp:103]: (style) Array index 'j' is used before limits check.
This commit is contained in:
Julien Nabet 2017-06-28 21:46:29 +02:00 committed by Robin Stuart
parent 0d6716a773
commit 3257a5c0af
6 changed files with 15 additions and 3 deletions

View File

@ -123,12 +123,16 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "Can't open output file");
free(bitmap_file_start);
free(bitmap);
return ZINT_ERROR_FILE_ACCESS;
}
#endif
bmp_file = stdout;
} else {
if (!(bmp_file = fopen(symbol->outfile, "wb"))) {
free(bitmap_file_start);
free(bitmap);
strcpy(symbol->errtxt, "Can't open output file (F00)");
return ZINT_ERROR_FILE_ACCESS;
}
@ -140,4 +144,4 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
free(bitmap_file_start);
free(bitmap);
return 0;
}
}

View File

@ -461,6 +461,7 @@ static int cc_b(struct zint_symbol *symbol, char source[], int cc_width) {
/* Now we have the variant we can load the data - from here on the same as MicroPDF417 code */
variant--;
assert(variant >= 0);
symbol->option_2 = MicroVariants[variant]; /* columns */
symbol->rows = MicroVariants[variant + 34]; /* rows */
k = MicroVariants[variant + 68]; /* number of EC CWs */

View File

@ -959,7 +959,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
i = 0;
while (i < tp) {
if (binary[i] == 'b') {
if ((i == 0) || ((i != 0) && (binary[i - 1] != 'b'))) {
if ((i == 0) || (binary[i - 1] != 'b')) {
/* start of binary data */
int binary_count; /* length of b256 data */

View File

@ -119,20 +119,24 @@ int save_raster_image_to_file(struct zint_symbol *symbol, int image_height, int
if (strlen(symbol->fgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed foreground colour target (F51)");
free(rotated_pixbuf);
return ZINT_ERROR_INVALID_OPTION;
}
if (strlen(symbol->bgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed background colour target (F52)");
free(rotated_pixbuf);
return ZINT_ERROR_INVALID_OPTION;
}
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed foreground colour target (F53)");
free(rotated_pixbuf);
return ZINT_ERROR_INVALID_OPTION;
}
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed background colour target (F54)");
free(rotated_pixbuf);
return ZINT_ERROR_INVALID_OPTION;
}
@ -181,6 +185,7 @@ int save_raster_image_to_file(struct zint_symbol *symbol, int image_height, int
#ifndef NO_PNG
error_number = png_pixel_plot(symbol, rotated_pixbuf);
#else
free(rotated_pixbuf);
return ZINT_ERROR_INVALID_OPTION;
#endif
break;
@ -503,6 +508,7 @@ int plot_raster_maxicode(struct zint_symbol *symbol, int rotate_angle, int data_
if (!(scaled_hexagon = (char *) malloc(hexagon_size * hexagon_size))) {
strcpy(symbol->errtxt, "Insufficient memory for pixel buffer (F56)");
free(scaled_hexagon);
free(pixelbuf);
return ZINT_ERROR_ENCODING_PROBLEM;
} else {
for (i = 0; i < (hexagon_size * hexagon_size); i++) {

View File

@ -266,6 +266,7 @@ int batch_process(struct zint_symbol *symbol, char *filename, int mirror_mode, c
char adjusted[2];
memset(buffer, 0, sizeof (unsigned char) * 7100);
memset(format_string, 0, sizeof (unsigned char) * 127);
if (symbol->outfile[0] == '\0') {
strcpy(format_string, "~~~~~.");
strcat(format_string, filetype);

View File

@ -100,7 +100,7 @@ void ExportWindow::process()
for(i = 0; i < lines; i++) {
datalen = 0;
for(j = inputpos; ((output_data[j] != '\n') && (j < output_data.length())); j++) {
for(j = inputpos; ((j < output_data.length()) && (output_data[j] != '\n') ); j++) {
datalen++;
}
dataString = output_data.mid(inputpos, datalen);