diff --git a/src/_imaging.c b/src/_imaging.c index f0ba22040..40bfbf2fe 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -490,8 +490,9 @@ getpixel(Imaging im, ImagingAccess access, int x, int y) case IMAGING_TYPE_FLOAT32: return PyFloat_FromDouble(pixel.f); case IMAGING_TYPE_SPECIAL: - if (strncmp(im->mode, "I;16", 4) == 0) + if (strncmp(im->mode, "I;16", 4) == 0) { return PyLong_FromLong(pixel.h); + } break; } @@ -1456,8 +1457,9 @@ _point(ImagingObject* self, PyObject* args) lut[i*4] = CLIP8(data[i]); lut[i*4+1] = CLIP8(data[i+256]); lut[i*4+2] = CLIP8(data[i+512]); - if (n > 768) + if (n > 768) { lut[i*4+3] = CLIP8(data[i+768]); + } } im = ImagingPoint(self->image, mode, (void*) lut); } else { @@ -1523,16 +1525,18 @@ _putdata(ImagingObject* self, PyObject* args) /* Plain string data */ for (i = y = 0; i < n; i += image->xsize, y++) { x = n - i; - if (x > (int) image->xsize) + if (x > (int) image->xsize) { x = image->xsize; + } memcpy(image->image8[y], p+i, x); } } else { /* Scaled and clipped string data */ for (i = x = y = 0; i < n; i++) { image->image8[y][x] = CLIP8((int) (p[i] * scale + offset)); - if (++x >= (int) image->xsize) + if (++x >= (int) image->xsize) { x = 0, y++; + } } } } else { @@ -1932,12 +1936,14 @@ im_setmode(ImagingObject* self, PyObject* args) /* color to color */ strcpy(im->mode, mode); im->bands = modelen; - if (!strcmp(mode, "RGBA")) + if (!strcmp(mode, "RGBA")) { (void) ImagingFillBand(im, 3, 255); + } } else { /* trying doing an in-place conversion */ - if (!ImagingConvertInPlace(im, mode)) + if (!ImagingConvertInPlace(im, mode)) { return NULL; + } } if (self->access) { diff --git a/src/_imagingft.c b/src/_imagingft.c index 795ab4d20..a9b00431a 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -406,11 +406,11 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject * direction = RAQM_DIRECTION_DEFAULT; if (dir) { - if (strcmp(dir, "rtl") == 0) + if (strcmp(dir, "rtl") == 0) { direction = RAQM_DIRECTION_RTL; - else if (strcmp(dir, "ltr") == 0) + } else if (strcmp(dir, "ltr") == 0) { direction = RAQM_DIRECTION_LTR; - else if (strcmp(dir, "ttb") == 0) { + } else if (strcmp(dir, "ttb") == 0) { direction = RAQM_DIRECTION_TTB; if (p_raqm.version_atleast == NULL || !(*p_raqm.version_atleast)(0, 7, 0)) { PyErr_SetString(PyExc_ValueError, "libraqm 0.7 or greater required for 'ttb' direction"); @@ -694,8 +694,9 @@ font_getsize(FontObject* self, PyObject* args) offset = -glyph_info[i].y_advance - face->glyph->metrics.height - face->glyph->metrics.vertBearingY; - if (offset < 0) + if (offset < 0) { y_max -= offset; + } } if (bbox.xMax > x_max) { diff --git a/src/encode.c b/src/encode.c index b285292f3..1d463e9c4 100644 --- a/src/encode.c +++ b/src/encode.c @@ -1085,8 +1085,9 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args) if (extra && extra_size > 0) { /* malloc check ok, length is from python parsearg */ char* p = malloc(extra_size); // Freed in JpegEncode, Case 5 - if (!p) + if (!p) { return PyErr_NoMemory(); + } memcpy(p, extra, extra_size); extra = p; } else { @@ -1097,7 +1098,9 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args) /* malloc check ok, length is from python parsearg */ char* pp = malloc(rawExifLen); // Freed in JpegEncode, Case 5 if (!pp) { - if (extra) free(extra); + if (extra) { + free(extra); + } return PyErr_NoMemory(); } memcpy(pp, rawExif, rawExifLen); diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index 5e69b067d..b0b794d72 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -1660,17 +1660,16 @@ convert(Imaging imOut, Imaging imIn, const char *mode, } } - if (!convert) + if (!convert) { #ifdef notdef return (Imaging) ImagingError_ValueError("conversion not supported"); #else - { - static char buf[256]; - /* FIXME: may overflow if mode is too large */ - sprintf(buf, "conversion from %s to %s not supported", imIn->mode, mode); - return (Imaging) ImagingError_ValueError(buf); - } + static char buf[256]; + /* FIXME: may overflow if mode is too large */ + sprintf(buf, "conversion from %s to %s not supported", imIn->mode, mode); + return (Imaging) ImagingError_ValueError(buf); #endif + } imOut = ImagingNew2Dirty(mode, imOut, imIn); if (!imOut) { diff --git a/src/libImaging/Crop.c b/src/libImaging/Crop.c index 29b4cf9d9..d136edbfc 100644 --- a/src/libImaging/Crop.c +++ b/src/libImaging/Crop.c @@ -32,11 +32,13 @@ ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1) } xsize = sx1 - sx0; - if (xsize < 0) + if (xsize < 0) { xsize = 0; + } ysize = sy1 - sy0; - if (ysize < 0) + if (ysize < 0) { ysize = 0; + } imOut = ImagingNewDirty(imIn->mode, xsize, ysize); if (!imOut) { diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index 35e6e4893..10aaae1f2 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -941,8 +941,9 @@ ellipse(Imaging im, int x0, int y0, int x1, int y1, } lx = x, ly = y; } - if (n == 0) + if (n == 0) { return 0; + } if (inner) { // Inner circle diff --git a/src/libImaging/GetBBox.c b/src/libImaging/GetBBox.c index dd875c557..9a8ae1f32 100644 --- a/src/libImaging/GetBBox.c +++ b/src/libImaging/GetBBox.c @@ -39,15 +39,18 @@ ImagingGetBBox(Imaging im, int bbox[4]) for (x = 0; x < im->xsize; x++) {\ if (im->image[y][x] & mask) {\ has_data = 1;\ - if (x < bbox[0])\ + if (x < bbox[0]) {\ bbox[0] = x;\ - if (x >= bbox[2])\ + }\ + if (x >= bbox[2]) {\ bbox[2] = x+1;\ + }\ }\ }\ if (has_data) {\ - if (bbox[1] < 0)\ - bbox[1] = y;\ + if (bbox[1] < 0) {\ + bbox[1] = y;\ + }\ bbox[3] = y+1;\ }\ } diff --git a/src/libImaging/GifDecode.c b/src/libImaging/GifDecode.c index 5728ae1ce..62170b15f 100644 --- a/src/libImaging/GifDecode.c +++ b/src/libImaging/GifDecode.c @@ -52,8 +52,9 @@ default:\ return -1;\ }\ - if (state->y < state->ysize)\ + if (state->y < state->ysize) {\ out = im->image8[state->y + state->yoff] + state->xoff;\ + }\ } @@ -70,24 +71,25 @@ ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_ssize_t if (!state->state) { - /* Initialise state */ - if (context->bits < 0 || context->bits > 12) { - state->errcode = IMAGING_CODEC_CONFIG; - return -1; - } + /* Initialise state */ + if (context->bits < 0 || context->bits > 12) { + state->errcode = IMAGING_CODEC_CONFIG; + return -1; + } - /* Clear code */ - context->clear = 1 << context->bits; + /* Clear code */ + context->clear = 1 << context->bits; - /* End code */ - context->end = context->clear + 1; + /* End code */ + context->end = context->clear + 1; - /* Interlace */ - if (context->interlace) { - context->interlace = 1; - context->step = context->repeat = 8; - } else - context->step = 1; + /* Interlace */ + if (context->interlace) { + context->interlace = 1; + context->step = context->repeat = 8; + } else { + context->step = 1; + } state->state = 1; } diff --git a/src/libImaging/Histo.c b/src/libImaging/Histo.c index b6f552ab3..050c2840f 100644 --- a/src/libImaging/Histo.c +++ b/src/libImaging/Histo.c @@ -179,8 +179,9 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) FLOAT32* in = (FLOAT32*) im->image32[y]; for (x = 0; x < im->xsize; x++) { i = (int) (((*in++)-fmin)*scale); - if (i >= 0 && i < 256) + if (i >= 0 && i < 256) { h->histogram[i]++; + } } } ImagingSectionLeave(&cookie); diff --git a/src/libImaging/Point.c b/src/libImaging/Point.c index 76c0e591d..b70840b07 100644 --- a/src/libImaging/Point.c +++ b/src/libImaging/Point.c @@ -219,8 +219,9 @@ ImagingPointTransform(Imaging imIn, double scale, double offset) if (!imIn || (strcmp(imIn->mode, "I") != 0 && strcmp(imIn->mode, "I;16") != 0 && - strcmp(imIn->mode, "F") != 0)) + strcmp(imIn->mode, "F") != 0)) { return (Imaging) ImagingError_ModeError(); + } imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize); if (!imOut) { diff --git a/src/libImaging/Quant.c b/src/libImaging/Quant.c index fdf1ea3b6..6c9f8d9b7 100644 --- a/src/libImaging/Quant.c +++ b/src/libImaging/Quant.c @@ -689,8 +689,12 @@ static void free_box_tree(BoxNode *n) { PixelList *p,*pp; - if (n->l) free_box_tree(n->l); - if (n->r) free_box_tree(n->r); + if (n->l) { + free_box_tree(n->l); + } + if (n->r) { + free_box_tree(n->r); + } for (p=n->head[0];p;p=pp) { pp=p->next[0]; free(p); @@ -1008,7 +1012,9 @@ compute_palette_from_median_cut( /* malloc check ok, using calloc */ if (!(avg[i]=calloc(nPaletteEntries, sizeof(uint32_t)))) { for(i=0;i<3;i++) { - if (avg[i]) free (avg[i]); + if (avg[i]) { + free (avg[i]); + } } free(count); return 0; diff --git a/src/libImaging/RawEncode.c b/src/libImaging/RawEncode.c index 3c593480b..fb4ab3346 100644 --- a/src/libImaging/RawEncode.c +++ b/src/libImaging/RawEncode.c @@ -41,8 +41,9 @@ ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) } state->count = state->bytes; state->bytes = bytes; - } else + } else { state->count = state->bytes; + } /* The "ystep" field specifies the orientation */ diff --git a/src/libImaging/XbmEncode.c b/src/libImaging/XbmEncode.c index cf72da619..d1bc086db 100644 --- a/src/libImaging/XbmEncode.c +++ b/src/libImaging/XbmEncode.c @@ -90,8 +90,9 @@ ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) bytes--; state->count = 0; } - } else + } else { *ptr++ = '\n'; + } bytes -= 5; diff --git a/src/libImaging/ZipEncode.c b/src/libImaging/ZipEncode.c index 6b44ed81a..0b4435678 100644 --- a/src/libImaging/ZipEncode.c +++ b/src/libImaging/ZipEncode.c @@ -307,8 +307,9 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) } - if (context->z_stream.avail_out == 0) + if (context->z_stream.avail_out == 0) { break; /* Buffer full */ + } case 2: