Browse Source

Checking for pointer values after malloc and realloc

master
Golikov Ivan 6 years ago
parent
commit
7d96d1591e
1 changed files with 10 additions and 1 deletions
  1. +10
    -1
      gaussian_blur/gblur.c

+ 10
- 1
gaussian_blur/gblur.c View File

@@ -136,6 +136,10 @@ int8_t gaussian_blur(struct image_data * original_image, struct image_data * blu
size_t num_channels = original_image->num_channels;

tmp = (JSAMPROW)malloc(x * num_channels);
if (tmp == NULL) {
return 1;
}

for (int j = 0; j < y; ++j) {
for (int i = 0; i < x; ++i) {
double sum = 0;
@@ -173,7 +177,12 @@ int8_t gaussian_blur(struct image_data * original_image, struct image_data * blu
}
}

tmp = realloc(tmp, y * num_channels);
JSAMPROW t = realloc(tmp, y * num_channels);
if (t == NULL) {
free(tmp);
} else {
tmp = t;
}

// Vertical box blur
for (int i = 0; i < x; ++i) {


Loading…
Cancel
Save