[PATCH] Return value checks, error messages, \n's, etc.
Darxus at chaosreigns.com
Darxus at chaosreigns.com
Mon Nov 22 21:34:43 PST 2010
5 \n's in prints
4 Return value checks
2 Additional error messages
2 Typos
1 Change return value for consistency (EGL_FALSE -> -1)
1 Check if array was created before writing to it
1 Corrected error message
---
clients/gears.c | 2 +-
clients/screenshot.c | 6 +++++-
clients/window.c | 17 ++++++++++-------
compositor/compositor-x11.c | 3 ++-
compositor/compositor.c | 11 +++++++++--
wayland/scanner.c | 4 ++--
wayland/wayland-server.c | 3 ++-
7 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/clients/gears.c b/clients/gears.c
index 7d3c310..6f47971 100644
--- a/clients/gears.c
+++ b/clients/gears.c
@@ -227,7 +227,7 @@ allocate_buffer(struct gears *gears)
gears->surface[gears->current]);
if (!eglMakeCurrent(gears->display, NULL, NULL, gears->context))
- die("faile to make context current\n");
+ die("failed to make context current\n");
glBindRenderbuffer(GL_RENDERBUFFER_EXT,
gears->color_rbo[gears->current]);
diff --git a/clients/screenshot.c b/clients/screenshot.c
index e9fa5aa..40867dc 100644
--- a/clients/screenshot.c
+++ b/clients/screenshot.c
@@ -61,7 +61,11 @@ int main(int argc, char *argv[])
}
screenshooter = NULL;
- wl_display_add_global_listener(display, handle_global, &screenshooter);
+ if (wl_display_add_global_listener(display, handle_global, &screenshooter) == NULL) {
+ fprintf(stderr, "failed to create listener\n");
+ return -1;
+ }
+
wl_display_iterate(display, WL_DISPLAY_READABLE);
if (screenshooter == NULL) {
fprintf(stderr, "display doesn't support screenshooter\n");
diff --git a/clients/window.c b/clients/window.c
index bc76937..12753bb 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -354,11 +354,11 @@ display_create_shm_surface(struct display *display,
data->length = stride * rectangle->height;
fd = mkstemp(filename);
if (fd < 0) {
- fprintf(stderr, "open %s failed: %m", filename);
+ fprintf(stderr, "open %s failed: %m\n", filename);
return NULL;
}
if (ftruncate(fd, data->length) < 0) {
- fprintf(stderr, "ftruncate failed: %m");
+ fprintf(stderr, "ftruncate failed: %m\n");
close(fd);
return NULL;
}
@@ -368,7 +368,7 @@ display_create_shm_surface(struct display *display,
unlink(filename);
if (data->map == MAP_FAILED) {
- fprintf(stderr, "mmap failed: %m");
+ fprintf(stderr, "mmap failed: %m\n");
close(fd);
return NULL;
}
@@ -1434,8 +1434,11 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
wl_list_init(&d->input_list);
/* Set up listener so we'll catch all events. */
- wl_display_add_global_listener(d->display,
- display_handle_global, d);
+ if (wl_display_add_global_listener(d->display,
+ display_handle_global, d) == NULL) {
+ fprintf(stderr, "failed to create listener\n");
+ return NULL;
+ }
/* Process connection events. */
wl_display_iterate(d->display, WL_DISPLAY_READABLE);
@@ -1447,7 +1450,7 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
}
if (drmGetMagic(fd, &magic)) {
- fprintf(stderr, "DRI2: failed to get drm magic");
+ fprintf(stderr, "DRI2: failed to get drm magic\n");
return NULL;
}
@@ -1475,7 +1478,7 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
}
if (!eglMakeCurrent(d->dpy, NULL, NULL, d->ctx)) {
- fprintf(stderr, "faile to make context current\n");
+ fprintf(stderr, "failed to make context current\n");
return NULL;
}
diff --git a/compositor/compositor-x11.c b/compositor/compositor-x11.c
index 3f6d842..5b9c630 100644
--- a/compositor/compositor-x11.c
+++ b/compositor/compositor-x11.c
@@ -133,6 +133,7 @@ dri2_connect(struct x11_compositor *c)
xfixes_query_cookie, &error);
if (xfixes_query == NULL ||
error != NULL || xfixes_query->major_version < 2) {
+ fprintf(stderr, "DRI2: major version < 2\n");
free(error);
return -1;
}
@@ -144,7 +145,7 @@ dri2_connect(struct x11_compositor *c)
if (dri2_query == NULL || error != NULL) {
fprintf(stderr, "DRI2: failed to query version\n");
free(error);
- return EGL_FALSE;
+ return -1;
}
c->dri2_major = dri2_query->major_version;
c->dri2_minor = dri2_query->minor_version;
diff --git a/compositor/compositor.c b/compositor/compositor.c
index ff24224..0878a4c 100644
--- a/compositor/compositor.c
+++ b/compositor/compositor.c
@@ -182,8 +182,10 @@ texture_from_png(const char *filename, int width, int height)
pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
width, height,
FALSE, &error);
- if (error != NULL)
+ if (error != NULL) {
+ fprintf(stderr, "could not open %s\n", filename);
return -1;
+ }
data = gdk_pixbuf_get_pixels(pixbuf);
@@ -989,7 +991,8 @@ notify_key(struct wlsc_input_device *device,
device->keys.size = (void *) end - device->keys.data;
if (state) {
k = wl_array_add(&device->keys, sizeof *k);
- *k = key;
+ if (k)
+ *k = key;
}
if (device->keyboard_focus != NULL)
@@ -1463,6 +1466,10 @@ int main(int argc, char *argv[])
}
display = wl_display_create();
+ if (display == NULL) {
+ fprintf(stderr, "failed to create display\n");
+ exit(EXIT_FAILURE);
+ }
if (getenv("DISPLAY"))
ec = x11_compositor_create(display, width, height);
diff --git a/wayland/scanner.c b/wayland/scanner.c
index 9d099fb..4326f3a 100644
--- a/wayland/scanner.c
+++ b/wayland/scanner.c
@@ -156,7 +156,7 @@ start_element(void *data, const char *element_name, const char **atts)
}
if (version == 0) {
- fprintf(stderr, "no interface version given\n");
+ fprintf(stderr, "version is 0\n");
exit(EXIT_FAILURE);
}
@@ -322,7 +322,7 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
if (!has_destructor && has_destroy) {
fprintf(stderr,
"interface %s has method named destroy but"
- "no destructor", interface->name);
+ "no destructor\n", interface->name);
exit(EXIT_FAILURE);
}
diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c
index 3ddfc33..3f6ad66 100644
--- a/wayland/wayland-server.c
+++ b/wayland/wayland-server.c
@@ -452,7 +452,8 @@ socket_data(int fd, uint32_t mask, void *data)
if (client_fd < 0)
fprintf(stderr, "failed to accept\n");
- wl_client_create(display, client_fd);
+ if (wl_client_create(display, client_fd) == NULL)
+ fprintf(stderr, "failed to create client\n");
}
WL_EXPORT int
--
1.7.1
More information about the wayland-devel
mailing list