[PATCH libinput] Fix to avoid use of undefined pointer values.
Jon A. Cruz
jonc at osg.samsung.com
Thu May 28 17:13:14 PDT 2015
If asprintf fails for any reason, the contents of the pointer
are undefined. While some platforms set it to NULL, there is no
guarantee that all will.
Signed-off-by: Jon A. Cruz <jonc at osg.samsung.com>
---
tools/libinput-list-devices.c | 59 ++++++++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c
index 6625173..b492e1d 100644
--- a/tools/libinput-list-devices.c
+++ b/tools/libinput-list-devices.c
@@ -120,24 +120,27 @@ calibration_default(struct libinput_device *device)
float calibration[6];
if (!libinput_device_config_calibration_has_matrix(device)) {
- asprintf(&str, "n/a");
+ if (asprintf(&str, "n/a") == -1)
+ str = NULL;
return str;
}
if (libinput_device_config_calibration_get_default_matrix(device,
calibration) == 0) {
- asprintf(&str, "identity matrix");
+ if (asprintf(&str, "identity matrix") == -1)
+ str = NULL;
return str;
}
- asprintf(&str,
- "%.2f %.2f %.2f %.2f %.2f %.2f",
- calibration[0],
- calibration[1],
- calibration[2],
- calibration[3],
- calibration[4],
- calibration[5]);
+ if (asprintf(&str,
+ "%.2f %.2f %.2f %.2f %.2f %.2f",
+ calibration[0],
+ calibration[1],
+ calibration[2],
+ calibration[3],
+ calibration[4],
+ calibration[5]) == -1)
+ str = NULL;
return str;
}
@@ -150,20 +153,22 @@ scroll_defaults(struct libinput_device *device)
scroll_methods = libinput_device_config_scroll_get_methods(device);
if (scroll_methods == LIBINPUT_CONFIG_SCROLL_NO_SCROLL) {
- asprintf(&str, "none");
+ if (asprintf(&str, "none") == -1)
+ str = NULL;
return str;
}
method = libinput_device_config_scroll_get_default_method(device);
- asprintf(&str,
- "%s%s%s%s%s%s",
- (method == LIBINPUT_CONFIG_SCROLL_2FG) ? "*" : "",
- (scroll_methods & LIBINPUT_CONFIG_SCROLL_2FG) ? "two-finger " : "",
- (method == LIBINPUT_CONFIG_SCROLL_EDGE) ? "*" : "",
- (scroll_methods & LIBINPUT_CONFIG_SCROLL_EDGE) ? "edge " : "",
- (method == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) ? "*" : "",
- (scroll_methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) ? "button" : "");
+ if (asprintf(&str,
+ "%s%s%s%s%s%s",
+ (method == LIBINPUT_CONFIG_SCROLL_2FG) ? "*" : "",
+ (scroll_methods & LIBINPUT_CONFIG_SCROLL_2FG) ? "two-finger " : "",
+ (method == LIBINPUT_CONFIG_SCROLL_EDGE) ? "*" : "",
+ (scroll_methods & LIBINPUT_CONFIG_SCROLL_EDGE) ? "edge " : "",
+ (method == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) ? "*" : "",
+ (scroll_methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) ? "button" : "") == -1)
+ str = NULL;
return str;
}
@@ -176,17 +181,19 @@ click_defaults(struct libinput_device *device)
click_methods = libinput_device_config_click_get_methods(device);
if (click_methods == LIBINPUT_CONFIG_CLICK_METHOD_NONE) {
- asprintf(&str, "none");
+ if (asprintf(&str, "none") == -1)
+ str = NULL;
return str;
}
method = libinput_device_config_click_get_default_method(device);
- asprintf(&str,
- "%s%s%s%s",
- (method == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) ? "*" : "",
- (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) ? "button-areas " : "",
- (method == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) ? "*" : "",
- (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) ? "clickfinger " : "");
+ if (asprintf(&str,
+ "%s%s%s%s",
+ (method == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) ? "*" : "",
+ (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) ? "button-areas " : "",
+ (method == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) ? "*" : "",
+ (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) ? "clickfinger " : "") == -1)
+ str = NULL;
return str;
}
--
2.1.0
More information about the wayland-devel
mailing list