Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bca6838e authored by Jing Mike's avatar Jing Mike Committed by Michael Bestas
Browse files

Check for Potential Null Pointer



After calling the function AndroidBitmap_lockPixels(), neither the
return value nor the returned pointers were checked for the possible
failure. So the pointers "source" & "destination" could have invalid
value.

Along with changes above, we also have some compile warnings and code
format cleaned.

Test: mmm packages/apps/Gallery2, presubmit check.

Change-Id: I28a5d678311cb963bacd6f7b96ca2e12d498d965
Signed-off-by: default avatarJing Mike <jingyangliu@eswincomputing.com>
parent 28a7edf3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ void JNIFUNCF(ImageFilterEdge, nativeApplyFilter, jobject bitmap, jint width, ji
    // set initial buffer to black
    memset(buf, 0, buf_len * sizeof(char));
    for (j = 3; j < buf_len; j+=4) {
        *(buf + j) = 255;  // set initial alphas
        *(buf + j) = (uint8_t) 255;  // set initial alphas
    }

    // apply sobel filter
@@ -120,7 +120,7 @@ void JNIFUNCF(ImageFilterEdge, nativeApplyFilter, jobject bitmap, jint width, ji
    int last_row = row_stride * (height - 1);
    memset((dst + last_row), 0, row_stride * sizeof(char));
    for (j = 3; j < row_stride; j+=4) {
        *(dst + last_row + j) = 255;  // set alphas
        *(dst + last_row + j) = (uint8_t) 255;  // set alphas
    }
    AndroidBitmap_unlockPixels(env, bitmap);
}
+7 −5
Original line number Diff line number Diff line
@@ -170,11 +170,13 @@ void JNIFUNCF(ImageFilterGeometry, nativeApplyFilterStraighten, jobject src, jin
    AndroidBitmap_lockPixels(env, src, (void**) &source);
    AndroidBitmap_lockPixels(env, dst, (void**) &destination);
    // TODO: implement straighten
    if (source != NULL && destination != NULL) {
        int i = 0;
        for (; i < len; i += 4) {
        destination[RED] = 128;
        destination[GREEN] = source[GREEN];
        destination[BLUE] = 128;
            destination[RED] = (uint8_t) 128;
            destination[GREEN] = (uint8_t) source[GREEN];
            destination[BLUE] = (uint8_t) 128;
        }
    }
    AndroidBitmap_unlockPixels(env, dst);
    AndroidBitmap_unlockPixels(env, src);
+26 −30
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){
        histB[(src[BLUE])]++;
    }
    int min_r = -1, min_g = -1, min_b = -1;
    int max_r = 0, max_g = 0,max_b = 0;
    int sum_r = 0, sum_g = 0, sum_b = 0;

    for (i = 1; i < RANGE-1; i++) {
@@ -47,17 +46,14 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){
        sum_g += g;
        sum_b += b;

        if (r>0){
            if (min_r < 0) min_r = i;
            max_r = i;
        if (r > 0 && min_r < 0) {
            min_r = i;
        }
        if (g>0){
            if (min_g < 0) min_g = i;
            max_g = i;
        if (g > 0 && min_g < 0) {
            min_g = i;
        }
        if (b>0){
            if (min_b < 0) min_b = i;
            max_b = i;
        if (b > 0 && min_b < 0) {
            min_b = i;
        }
    }