diff options
-rw-r--r-- | Makefile.am | 14 | ||||
-rw-r--r-- | clients/multi-resource.c | 8 | ||||
-rw-r--r-- | clients/terminal.c | 8 | ||||
-rw-r--r-- | clients/wscreensaver-glue.c | 6 | ||||
-rw-r--r-- | shared/config-parser.c | 10 | ||||
-rw-r--r-- | shared/option-parser.c | 10 | ||||
-rw-r--r-- | shared/str-util.c | 133 | ||||
-rw-r--r-- | shared/str-util.h | 43 | ||||
-rw-r--r-- | src/compositor-rdp.c | 5 | ||||
-rw-r--r-- | src/libbacklight.c | 4 | ||||
-rw-r--r-- | tests/strutil-test.c | 322 | ||||
-rw-r--r-- | xwayland/launcher.c | 3 |
12 files changed, 537 insertions, 29 deletions
diff --git a/Makefile.am b/Makefile.am index 5819b199..b08932d8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -910,6 +910,8 @@ libshared_la_SOURCES = \ shared/config-parser.h \ shared/file-util.c \ shared/file-util.h \ + shared/str-util.c \ + shared/str-util.h \ shared/os-compatibility.c \ shared/os-compatibility.h @@ -949,6 +951,7 @@ internal_tests = \ shared_tests = \ config-parser.test \ + strutil.test \ vertex-clip.test module_tests = \ @@ -1030,6 +1033,9 @@ libtest_runner_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS) config_parser_test_SOURCES = tests/config-parser-test.c config_parser_test_LDADD = libshared.la libtest-runner.la $(COMPOSITOR_LIBS) +strutil_test_SOURCES = tests/strutil-test.c +strutil_test_LDADD = libshared.la libtest-runner.la $(COMPOSITOR_LIBS) + vertex_clip_test_SOURCES = \ tests/vertex-clip-test.c \ src/vertex-clipping.c \ @@ -1167,9 +1173,11 @@ endif if BUILD_SETBACKLIGHT noinst_PROGRAMS += setbacklight -setbacklight_SOURCES = \ - tests/setbacklight.c \ - src/libbacklight.c \ +setbacklight_SOURCES = \ + tests/setbacklight.c \ + shared/str-util.c \ + shared/str-util.h \ + src/libbacklight.c \ src/libbacklight.h setbacklight_CFLAGS = $(AM_CFLAGS) $(SETBACKLIGHT_CFLAGS) setbacklight_LDADD = $(SETBACKLIGHT_LIBS) diff --git a/clients/multi-resource.c b/clients/multi-resource.c index 0dc2c74b..5d8d2ed0 100644 --- a/clients/multi-resource.c +++ b/clients/multi-resource.c @@ -39,6 +39,7 @@ #include <wayland-client.h> #include "../shared/os-compatibility.h" +#include "../shared/str-util.h" struct device { enum { KEYBOARD, POINTER } type; @@ -443,14 +444,11 @@ create_device(struct display *display, const char *time_desc, int type) return -1; } - errno = 0; - start_time = strtoul(time_desc, &tail, 10); - if (errno) + if (!weston_strtoi(time_desc, &tail, 10, &start_time)) goto error; if (*tail == ':') { - end_time = strtoul(tail + 1, &tail, 10); - if (errno || *tail != '\0') + if (!weston_strtoi(tail + 1, &tail, 10, &end_time)) goto error; } else if (*tail != '\0') { goto error; diff --git a/clients/terminal.c b/clients/terminal.c index d7345d34..ead40fd8 100644 --- a/clients/terminal.c +++ b/clients/terminal.c @@ -43,6 +43,7 @@ #include <wayland-client.h> #include "../shared/config-parser.h" +#include "../shared/str-util.h" #include "window.h" static int option_fullscreen; @@ -1277,11 +1278,12 @@ static void handle_osc(struct terminal *terminal) { char *p; - int code; + int code = -1; terminal->escape[terminal->escape_length++] = '\0'; p = &terminal->escape[2]; - code = strtol(p, &p, 10); + + weston_strtoi(p, &p, 10, &code); if (*p == ';') p++; switch (code) { @@ -1324,7 +1326,7 @@ handle_escape(struct terminal *terminal) p++; i++; } else { - args[i] = strtol(p, &p, 10); + weston_strtoi(p, &p, 10, &args[i]); set[i] = 1; } } diff --git a/clients/wscreensaver-glue.c b/clients/wscreensaver-glue.c index 55d0a8c7..ce5f92b6 100644 --- a/clients/wscreensaver-glue.c +++ b/clients/wscreensaver-glue.c @@ -21,6 +21,7 @@ */ #include "wscreensaver-glue.h" +#include "../shared/str-util.h" double frand(double f) { @@ -70,6 +71,7 @@ read_xpm_color(uint32_t *ctable, const char *line) char cstr[10]; char *end; uint32_t value; + bool conv; if (sscanf(line, "%1c c %9s", &key, cstr) < 2) { fprintf(stderr, "%s: error in XPM color definition '%s'\n", @@ -77,11 +79,11 @@ read_xpm_color(uint32_t *ctable, const char *line) return; } - value = strtol(&cstr[1], &end, 16); + conv = weston_strtoui(&cstr[1], NULL, 16, &value); if (strcmp(cstr, "None") == 0) ctable[key] = 0x00000000; - else if (cstr[0] != '#' || !(cstr[1] != '\0' && *end == '\0')) { + else if (cstr[0] != '#' || !conv) { fprintf(stderr, "%s: error interpreting XPM color '%s'\n", progname, cstr); return; diff --git a/shared/config-parser.c b/shared/config-parser.c index 8519eb68..49296a71 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -35,7 +35,9 @@ #include <errno.h> #include <wayland-util.h> + #include "config-parser.h" +#include "str-util.h" #define container_of(ptr, type, member) ({ \ const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \ @@ -160,7 +162,6 @@ weston_config_section_get_int(struct weston_config_section *section, int32_t *value, int32_t default_value) { struct weston_config_entry *entry; - char *end; entry = config_section_get_entry(section, key); if (entry == NULL) { @@ -169,8 +170,7 @@ weston_config_section_get_int(struct weston_config_section *section, return -1; } - *value = strtol(entry->value, &end, 0); - if (*end != '\0') { + if (!weston_strtoi(entry->value, NULL, 0, value)) { *value = default_value; errno = EINVAL; return -1; @@ -186,7 +186,6 @@ weston_config_section_get_uint(struct weston_config_section *section, uint32_t *value, uint32_t default_value) { struct weston_config_entry *entry; - char *end; entry = config_section_get_entry(section, key); if (entry == NULL) { @@ -195,8 +194,7 @@ weston_config_section_get_uint(struct weston_config_section *section, return -1; } - *value = strtoul(entry->value, &end, 0); - if (*end != '\0') { + if (!weston_strtoui(entry->value, NULL, 0, value)) { *value = default_value; errno = EINVAL; return -1; diff --git a/shared/option-parser.c b/shared/option-parser.c index 70612689..dad5e1d3 100644 --- a/shared/option-parser.c +++ b/shared/option-parser.c @@ -27,21 +27,19 @@ #include <stdio.h> #include <string.h> #include <assert.h> +#include <wayland-util.h> #include "config-parser.h" +#include "str-util.h" static int handle_option(const struct weston_option *option, char *value) { - char* p; - switch (option->type) { case WESTON_OPTION_INTEGER: - * (int32_t *) option->data = strtol(value, &p, 0); - return *value && !*p; + return weston_strtoi(value, NULL, 0, (int32_t *)option->data); case WESTON_OPTION_UNSIGNED_INTEGER: - * (uint32_t *) option->data = strtoul(value, &p, 0); - return *value && !*p; + return weston_strtoui(value, NULL, 0, (uint32_t *)option->data); case WESTON_OPTION_STRING: * (char **) option->data = strdup(value); return 1; diff --git a/shared/str-util.c b/shared/str-util.c new file mode 100644 index 00000000..448f7b04 --- /dev/null +++ b/shared/str-util.c @@ -0,0 +1,133 @@ +/* + * Copyright © 2014 Intel Corporation. + * + * Contact: Imran Zaman <imran.zaman@linux.intel.com> + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "config.h" + +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <ctype.h> +#include <limits.h> + +#ifdef IN_WESTON +#include <wayland-util.h> +#else +#define WL_EXPORT +#endif + +#include "str-util.h" + +static bool +convert_strtol(const char *str, char **endptr, int base, long *val) +{ + char *end = NULL; + long v; + int prev_errno = errno; + + if (!str || !val) + return false; + if (!endptr) + endptr = &end; + + errno = 0; + v = strtol(str, endptr, base); + if (errno != 0 || *endptr == str || **endptr != '\0') + return false; + + errno = prev_errno; + *val = v; + return true; +} + +static bool +convert_strtoul (const char *str, char **endptr, int base, unsigned long *val) +{ + char *end = NULL; + unsigned long v; + int i = 0; + int prev_errno = errno; + + if (!str || !val) + return false; + + /* check for negative numbers */ + while (str[i]) { + if (!isspace(str[i])) { + if (str[i] == '-') + return false; + else + break; + } + i++; + } + + if (!endptr) + endptr = &end; + + errno = 0; + v = strtoul(str, endptr, base); + if (errno != 0 || *endptr == str || **endptr != '\0') + return false; + + errno = prev_errno; + *val = v; + return true; +} + +WL_EXPORT bool +weston_strtoi(const char *str, char **endptr, int base, int *val) +{ + long v; + + if (!convert_strtol(str, endptr, base, &v) || v > INT_MAX + || v < INT_MIN) + return false; + + *val = (int)v; + return true; +} + +WL_EXPORT bool +weston_strtol(const char *str, char **endptr, int base, long *val) +{ + return convert_strtol(str, endptr, base, val); +} + +WL_EXPORT bool +weston_strtoui(const char *str, char **endptr, int base, unsigned int *val) +{ + unsigned long v; + + if (!convert_strtoul(str, endptr, base, &v) || v > UINT_MAX) + return false; + + *val = (unsigned int)v; + return true; +} + +WL_EXPORT bool +weston_strtoul(const char *str, char **endptr, int base, unsigned long *val) +{ + return convert_strtoul(str, endptr, base, val); +} diff --git a/shared/str-util.h b/shared/str-util.h new file mode 100644 index 00000000..bb6322d4 --- /dev/null +++ b/shared/str-util.h @@ -0,0 +1,43 @@ +/* + * Copyright © 2014 Intel Corporation. + * + * Contact: Imran Zaman <imran.zaman@linux.intel.com> + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef WESTON_STR_UTIL_H +#define WESTON_STR_UTIL_H + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +bool weston_strtoi(const char *str, char **endptr, int base, int *val); +bool weston_strtol(const char *str, char **endptr, int base, long *val); +bool weston_strtoui(const char *str, char **endptr, int base, unsigned int *val); +bool weston_strtoul(const char *str, char **endptr, int base, unsigned long *val); + +#ifdef __cplusplus +} +#endif + +#endif /* WESTON_STR_UTIL_H */ diff --git a/src/compositor-rdp.c b/src/compositor-rdp.c index 4091bace..9d45edd0 100644 --- a/src/compositor-rdp.c +++ b/src/compositor-rdp.c @@ -65,6 +65,8 @@ #include "compositor.h" #include "pixman-renderer.h" +#include "../shared/str-util.h" + #define MAX_FREERDP_FDS 32 #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10) #define RDP_MODE_FREQ 60 * 1000 @@ -1214,7 +1216,8 @@ rdp_compositor_create(struct wl_display *display, goto err_output; } - fd = strtoul(fd_str, NULL, 10); + if (!weston_strtoi(fd_str, NULL, 10, &fd)) + fd = -1; if (rdp_peer_init(freerdp_peer_new(fd), c)) goto err_output; } diff --git a/src/libbacklight.c b/src/libbacklight.c index 54f33182..692c0071 100644 --- a/src/libbacklight.c +++ b/src/libbacklight.c @@ -43,6 +43,8 @@ #include <string.h> #include <errno.h> +#include "../shared/str-util.h" + static long backlight_get(struct backlight *backlight, char *node) { char buffer[100]; @@ -64,7 +66,7 @@ static long backlight_get(struct backlight *backlight, char *node) goto out; } - value = strtol(buffer, NULL, 10); + weston_strtol(buffer, NULL, 10, &value); ret = value; out: if (fd >= 0) diff --git a/tests/strutil-test.c b/tests/strutil-test.c new file mode 100644 index 00000000..7616549b --- /dev/null +++ b/tests/strutil-test.c @@ -0,0 +1,322 @@ +/* + * Copyright © 2014 Intel Corporation. + * + * Contact: Imran Zaman <imran.zaman@linux.intel.com> + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +#include "weston-test-runner.h" + +#include "../shared/str-util.h" + +TEST(test_weston_strtol) +{ + bool ret; + long val = -1; + char *end = NULL, *str = NULL; + + ret = weston_strtol(NULL, NULL, 10, &val); + assert(ret == false); + assert(val == -1); + + ret = weston_strtol(NULL, NULL, 10, NULL); + assert(ret == false); + + str = "12"; + ret = weston_strtol(str, NULL, 10, &val); + assert(ret == true); + assert(val == 12); + + ret = weston_strtol(str, &end, 10, &val); + assert(end != NULL); + assert(*end == '\0'); + + str = "-12"; val = -1; + ret = weston_strtol(str, &end, 10, &val); + assert(ret == true); + assert(val == -12); + + str = "0x12"; val = -1; + ret = weston_strtol(str, &end, 16, &val); + assert(ret == true); + assert(val == 0x12); + + str = "A"; val = -1; + ret = weston_strtol(str, &end, 16, &val); + assert(ret == true); + assert(val == 10); + + str = "-0x20"; val = -1; + ret = weston_strtol(str, &end, 16, &val); + assert(ret == true); + assert(val == -0x20); + + str = "0012"; val = -1; + ret = weston_strtol(str, &end, 8, &val); + assert(ret == true); + assert(val == 10); + + str = "0101"; val = -1; + ret = weston_strtol(str, &end, 2, &val); + assert(ret == true); + assert(val == 5); + + str = "s12"; val = -1; + ret = weston_strtol(str, NULL, 10, &val); + assert(ret == false); + assert(val == -1); + + ret = weston_strtol(str, &end, 10, &val); + assert(end == str); + + str = "214748364789L"; val = -1; + ret = weston_strtol(str, NULL, 10, &val); + assert(ret == false); + assert(val == -1); + + str = ""; val = -1; + ret = weston_strtol(str, NULL, 10, &val); + assert(ret == false); + assert(val == -1); +} + +TEST(test_weston_strtoul) +{ + bool ret; + unsigned long val = 0; + char *end = NULL, *str = NULL; + + ret = weston_strtoul(NULL, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + ret = weston_strtoul(NULL, NULL, 10, NULL); + assert(ret == false); + + str = "15"; + ret = weston_strtoul(str, NULL, 10, &val); + assert(ret == true); + assert(val == 15); + + ret = weston_strtoul(str, &end, 10, &val); + assert(end != NULL); + assert(*end == '\0'); + + str = "0x12"; val = 0; + ret = weston_strtoul(str, &end, 16, &val); + assert(ret == true); + assert(val == 18); + + str = "A"; val = 0; + ret = weston_strtoul(str, &end, 16, &val); + assert(ret == true); + assert(val == 10); + + str = "0012"; val = 0; + ret = weston_strtoul(str, &end, 8, &val); + assert(ret == true); + assert(val == 10); + + str = "0101"; val = 0; + ret = weston_strtoul(str, &end, 2, &val); + assert(ret == true); + assert(val == 5); + + str = "s15"; val = 0; + ret = weston_strtoul(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + ret = weston_strtoul(str, &end, 10, &val); + assert(end == str); + + str = "429496729533UL"; val = 0; + ret = weston_strtoul(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + str = "-1"; val = 0; + ret = weston_strtoul(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + str = " -1234"; val = 0; + ret = weston_strtoul(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + str = ""; val = 0; + ret = weston_strtoul(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); +} + +TEST(test_weston_strtoi) +{ + bool ret; + int val = -1; + char *end = NULL, *str = NULL; + + ret = weston_strtoi(NULL, NULL, 10, &val); + assert(ret == false); + assert(val == -1); + + ret = weston_strtoi(NULL, NULL, 10, NULL); + assert(ret == false); + + str = "12"; + ret = weston_strtoi(str, NULL, 10, &val); + assert(ret == true); + assert(val == 12); + + ret = weston_strtoi(str, &end, 10, &val); + assert(end != NULL); + assert(*end == '\0'); + + str = "-12"; val = -1; + ret = weston_strtoi(str, &end, 10, &val); + assert(ret == true); + assert(val == -12); + + str = "0x12"; val = -1; + ret = weston_strtoi(str, &end, 16, &val); + assert(ret == true); + assert(val == 0x12); + + str = "A"; val = -1; + ret = weston_strtoi(str, &end, 16, &val); + assert(ret == true); + assert(val == 10); + + str = "-0x20"; val = -1; + ret = weston_strtoi(str, &end, 16, &val); + assert(ret == true); + assert(val == -0x20); + + str = "0012"; val = -1; + ret = weston_strtoi(str, &end, 8, &val); + assert(ret == true); + assert(val == 10); + + str = "0101"; val = -1; + ret = weston_strtoi(str, &end, 2, &val); + assert(ret == true); + assert(val == 5); + + str = "-5"; val = -1; + ret = weston_strtoi(str, &end, 2, &val); + assert(ret == true); + assert(val == -5); + + str = "s12"; val = -1; + ret = weston_strtoi(str, NULL, 10, &val); + assert(ret == false); + assert(val == -1); + + ret = weston_strtoi(str, &end, 10, &val); + assert(end == str); + + str = "214748364789L"; val = -1; + ret = weston_strtoi(str, NULL, 10, &val); + assert(ret == false); + assert(val == -1); + + str = ""; val = -1; + ret = weston_strtoi(str, NULL, 10, &val); + assert(ret == false); + assert(val == -1); +} + +TEST(test_weston_strtoui) +{ + bool ret; + unsigned int val = 0; + char *end = NULL, *str = NULL; + + ret = weston_strtoui(NULL, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + ret = weston_strtoui(NULL, NULL, 10, NULL); + assert(ret == false); + + str = "15"; + ret = weston_strtoui(str, NULL, 10, &val); + assert(ret == true); + assert(val == 15); + + ret = weston_strtoui(str, &end, 10, &val); + assert(end != NULL); + assert(*end == '\0'); + + str = "0x12"; val = 0; + ret = weston_strtoui(str, &end, 16, &val); + assert(ret == true); + assert(val == 18); + + str = "A"; val = 0; + ret = weston_strtoui(str, &end, 16, &val); + assert(ret == true); + assert(val == 10); + + str = "0012"; val = 0; + ret = weston_strtoui(str, &end, 8, &val); + assert(ret == true); + assert(val == 10); + + str = "0101"; val = 0; + ret = weston_strtoui(str, &end, 2, &val); + assert(ret == true); + assert(val == 5); + + str = "s15"; val = 0; + ret = weston_strtoui(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + ret = weston_strtoui(str, &end, 10, &val); + assert(end == str); + + str = "429496729533UL"; val = 0; + ret = weston_strtoui(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + str = "-1"; val = 0; + ret = weston_strtoui(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + str = " -1234"; val = 0; + ret = weston_strtoui(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); + + str = ""; val = 0; + ret = weston_strtoui(str, NULL, 10, &val); + assert(ret == false); + assert(val == 0); +} diff --git a/xwayland/launcher.c b/xwayland/launcher.c index df2efd2e..4ba2031a 100644 --- a/xwayland/launcher.c +++ b/xwayland/launcher.c @@ -284,8 +284,7 @@ create_lockfile(int display, char *lockfile, size_t lsize) return -1; } - other = strtol(pid, &end, 0); - if (end != pid + 10) { + if (!weston_strtoi(pid, &end, 0, &other) || end != pid + 10) { weston_log("can't parse lock file %s\n", lockfile); close(fd); |