[cairo-bugs] [Bug 12102] New: uninitialized var

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Wed Aug 22 11:54:02 PDT 2007


http://bugs.freedesktop.org/show_bug.cgi?id=12102

           Summary: uninitialized var
           Product: cairo
           Version: 1.2.0
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: medium
         Component: general
        AssignedTo: cworth at cworth.org
        ReportedBy: freedesktop at behdad.org
         QAContact: cairo-bugs at cairographics.org


I'm getting:

cairo-glitz-surface.c:300: warning: 'n' is used uninitialized in this function

That code is:

    /* restore the clip, if any */
    if (surface->has_clip) {
        glitz_box_t *box;
        int n;

        box = _cairo_glitz_get_boxes_from_region (&surface->clip, &n);
        if (box == NULL && n != 0) {
            free (pixels);
            return CAIRO_STATUS_NO_MEMORY;
        }

        glitz_surface_set_clip_region (surface->surface, 0, 0, box, n);

        free (box);
    }

So let's make _cairo_glitz_get_boxes_from_region() always set n.  That function
is:

static glitz_box_t *
_cairo_glitz_get_boxes_from_region (cairo_region_t *region, int *nboxes)
{
    cairo_box_int_t *cboxes;
    glitz_box_t *gboxes;
    int n, i;

    if (_cairo_region_get_boxes (region, &n, &cboxes) != CAIRO_STATUS_SUCCESS)
        return NULL;

    *nboxes = n;
    if (n == 0)
        return NULL;

    ...

So if _cairo_region_get_boxes() returns NULL, n is indeed left uninitialized. 
That's one thing to fix, but also should ensure that _cairo_region_get_boxes()
sets num_boxes for sure.  That function is looking:

cairo_int_status_t
_cairo_region_get_boxes (cairo_region_t *region, int *num_boxes,
cairo_box_int_t **boxes)
{
    int nboxes;
    pixman_box16_t *pboxes;
    cairo_box_int_t *cboxes;
    int i;

    pboxes = pixman_region_rectangles (&region->rgn, &nboxes);

    if (nboxes == 0) {
        *num_boxes = 0;
        *boxes = NULL;
        return CAIRO_STATUS_SUCCESS;
    }

    cboxes = _cairo_malloc_ab (nboxes, sizeof(cairo_box_int_t));
    if (cboxes == NULL)
        return CAIRO_STATUS_NO_MEMORY;
    ...


So again, on out-of-memory, num_boxes is not set.  Easy fix to this one is to
move the *num_boxes = nboxes to the top.  Or, simply pass num_boxes to
pixman_region_rectangles().


-- 
Configure bugmail: http://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug, or are watching the QA contact.


More information about the cairo-bugs mailing list