[PATCH weston v4 5/5] Switch to use safe_strtoint instead of strtol

Pekka Paalanen ppaalanen at gmail.com
Mon Aug 8 11:55:14 UTC 2016


On Wed,  3 Aug 2016 17:40:52 -0700
Bryce Harrington <bryce at osg.samsung.com> wrote:

> Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>
> Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> ---
>  compositor/main.c           |  7 +++----
>  compositor/systemd-notify.c |  9 +++------
>  libweston/compositor.c      |  9 +++------
>  libweston/libbacklight.c    | 11 +++++------
>  shared/config-parser.c      |  7 ++-----
>  shared/option-parser.c      |  5 ++---
>  xwayland/launcher.c         |  7 +++----
>  7 files changed, 21 insertions(+), 34 deletions(-)
> 

> diff --git a/compositor/systemd-notify.c b/compositor/systemd-notify.c
> index 6104124..49e51f4 100644
> --- a/compositor/systemd-notify.c
> +++ b/compositor/systemd-notify.c
> @@ -25,12 +25,13 @@
>  
>  #include "config.h"
>  
> -#include <errno.h>
>  #include <stdlib.h>
>  #include <systemd/sd-daemon.h>
>  #include <sys/socket.h>
>  #include <wayland-server.h>
> +
>  #include "shared/helpers.h"
> +#include "shared/string-helpers.h"
>  #include "shared/zalloc.h"
>  #include "compositor.h"
>  
> @@ -116,7 +117,6 @@ WL_EXPORT int
>  module_init(struct weston_compositor *compositor,
>  	    int *argc, char *argv[])
>  {
> -	char *tail;
>  	char *watchdog_time_env;
>  	struct wl_event_loop *loop;
>  	long watchdog_time_conv;
> @@ -140,13 +140,10 @@ module_init(struct weston_compositor *compositor,
>  	 * by systemd to transfer 'WatchdogSec' watchdog timeout
>  	 * setting from service file.*/
>  	watchdog_time_env = getenv("WATCHDOG_USEC");
> -
>  	if (!watchdog_time_env)
>  		return 0;
>  
> -	errno = 0;
> -	watchdog_time_conv = strtol(watchdog_time_env, &tail, 10);
> -	if (errno != 0 || tail == watchdog_time_env || *tail != '\0')
> +	if (!safe_strtoint(watchdog_time_env, &watchdog_time_conv))
>  		return 0;
>  
>  	/* Convert 'WATCHDOG_USEC' to milliseconds and notify

Hi,

there's a new warning:

/home/pq/git/weston/compositor/systemd-notify.c: In function ‘module_init’:
/home/pq/git/weston/compositor/systemd-notify.c:146:40: warning: passing argument 2 of ‘safe_strtoint’ from incompatible pointer type
  if (!safe_strtoint(watchdog_time_env, &watchdog_time_conv))
                                        ^
In file included from /home/pq/git/weston/compositor/systemd-notify.c:34:0:
/home/pq/git/weston/shared/string-helpers.h:45:1: note: expected ‘int32_t *’ but argument is of type ‘long int *’
 safe_strtoint(const char *str, int32_t *value)
 ^

Please CC me if you want me to test a patch for this. I suppose int32_t
should be fine?


Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 811 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20160808/a4857a9f/attachment.sig>


More information about the wayland-devel mailing list