diff options
Diffstat (limited to 'src/surface')
-rw-r--r-- | src/surface/ram.c | 37 | ||||
-rw-r--r-- | src/surface/wld.c | 26 | ||||
-rw-r--r-- | src/surface/x.c | 17 |
3 files changed, 61 insertions, 19 deletions
diff --git a/src/surface/ram.c b/src/surface/ram.c index 4deabda..da769b6 100644 --- a/src/surface/ram.c +++ b/src/surface/ram.c @@ -35,19 +35,35 @@ static int ram_defaults(nsfb_t *nsfb) static int ram_initialise(nsfb_t *nsfb) { - size_t size = (nsfb->width * nsfb->height * nsfb->bpp) / 8; + size_t size; + uint8_t *fbptr; - nsfb->ptr = realloc(nsfb->ptr, size); + size = (nsfb->width * nsfb->height * nsfb->bpp) / 8; + fbptr = realloc(nsfb->ptr, size); + if (fbptr == NULL) { + return -1; + } + + nsfb->ptr = fbptr; nsfb->linelen = (nsfb->width * nsfb->bpp) / 8; return 0; } -static int ram_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format) +static int +ram_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format) { int startsize; int endsize; + int prev_width; + int prev_height; + enum nsfb_format_e prev_format; + + prev_width = nsfb->width; + prev_height = nsfb->height; + prev_format = nsfb->format; + startsize = (nsfb->width * nsfb->height * nsfb->bpp) / 8; if (width > 0) { @@ -65,10 +81,23 @@ static int ram_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_forma /* select soft plotters appropriate for format */ select_plotters(nsfb); + /* reallocate surface memory if necessary */ endsize = (nsfb->width * nsfb->height * nsfb->bpp) / 8; if ((nsfb->ptr != NULL) && (startsize != endsize)) { - nsfb->ptr = realloc(nsfb->ptr, endsize); + uint8_t *fbptr; + fbptr = realloc(nsfb->ptr, endsize); + if (fbptr == NULL) { + /* allocation failed so put everything back as it was */ + nsfb->width = prev_width; + nsfb->height = prev_height; + nsfb->format = prev_format; + select_plotters(nsfb); + + return -1; + } + nsfb->ptr = fbptr; } + nsfb->linelen = (nsfb->width * nsfb->bpp) / 8; return 0; diff --git a/src/surface/wld.c b/src/surface/wld.c index 29f9ae2..9ef3c40 100644 --- a/src/surface/wld.c +++ b/src/surface/wld.c @@ -48,7 +48,7 @@ struct wld_connection { struct wl_display *display; /**< connection object */ struct wl_registry *registry; /**< registry object */ - /** compositor object, available once teh registry messages have + /** compositor object, available once the registry messages have * been processed */ struct wl_compositor *compositor; @@ -975,13 +975,14 @@ pointer_handle_motion(void *data, UNUSED(time); event = calloc(1, sizeof(struct wld_event)); + if (event != NULL) { + event->event.type = NSFB_EVENT_MOVE_ABSOLUTE; + event->event.value.vector.x = wl_fixed_to_int(sx_w); + event->event.value.vector.y = wl_fixed_to_int(sy_w); + event->event.value.vector.z = 0; - event->event.type = NSFB_EVENT_MOVE_ABSOLUTE; - event->event.value.vector.x = wl_fixed_to_int(sx_w); - event->event.value.vector.y = wl_fixed_to_int(sy_w); - event->event.value.vector.z = 0; - - enqueue_wld_event(input->connection, event); + enqueue_wld_event(input->connection, event); + } } static void @@ -997,7 +998,9 @@ pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial, UNUSED(time); event = calloc(1, sizeof(struct wld_event)); - + if (event == NULL) { + return; + } if (state == WL_POINTER_BUTTON_STATE_PRESSED) { event->event.type = NSFB_EVENT_KEY_DOWN; } else { @@ -1259,7 +1262,6 @@ new_connection(void) struct wld_connection* connection; connection = calloc(1, sizeof(struct wld_connection)); - if (connection == NULL) { return NULL; } @@ -1456,8 +1458,9 @@ os_create_anonymous_file(off_t size) } name = malloc(strlen(path) + sizeof(template)); - if (!name) + if (name == NULL) { return -1; + } strcpy(name, path); strcat(name, template); @@ -1657,8 +1660,9 @@ static int x_initialise(nsfb_t *nsfb) return -1; xstate = calloc(1, sizeof(xstate_t)); - if (xstate == NULL) + if (xstate == NULL) { return -1; /* no memory */ + } /* open connection with the server */ xstate->connection = xcb_connect(NULL, NULL); diff --git a/src/surface/x.c b/src/surface/x.c index f5ee01b..c011b38 100644 --- a/src/surface/x.c +++ b/src/surface/x.c @@ -846,10 +846,19 @@ static int x_initialise(nsfb_t *nsfb) mask, values); /* set size hits on window */ hints = xcb_alloc_size_hints(); - xcb_size_hints_set_max_size(hints, xstate->image->width, xstate->image->height); - xcb_size_hints_set_min_size(hints, xstate->image->width, xstate->image->height); - xcb_set_wm_size_hints(xstate->connection, xstate->window, WM_NORMAL_HINTS, hints); - xcb_free_size_hints(hints); + if (hints != NULL) { + xcb_size_hints_set_max_size(hints, + xstate->image->width, + xstate->image->height); + xcb_size_hints_set_min_size(hints, + xstate->image->width, + xstate->image->height); + xcb_set_wm_size_hints(xstate->connection, + xstate->window, + WM_NORMAL_HINTS, + hints); + xcb_free_size_hints(hints); + } /* create backing pixmap */ xstate->pmap = xcb_generate_id(xstate->connection); |