[PATCH:rgb] Use asprintf() instead of malloc/strcpy/strcat, if its available
walter harms
wharms at bfs.de
Sat Oct 25 11:01:59 PDT 2014
Am 25.10.2014 19:32, schrieb Alan Coopersmith:
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
> configure.ac | 3 +++
> showrgb.c | 7 +++++++
> 2 files changed, 10 insertions(+)
>
> diff --git a/configure.ac b/configure.ac
> index 534e41d..bf7974a 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -27,6 +27,7 @@ AC_INIT([rgb], [1.0.5],
> [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [rgb])
> AC_CONFIG_SRCDIR([Makefile.am])
> AC_CONFIG_HEADERS([config.h])
> +AC_USE_SYSTEM_EXTENSIONS
>
> # Initialize Automake
> AM_INIT_AUTOMAKE([foreign dist-bzip2])
> @@ -37,6 +38,8 @@ m4_ifndef([XORG_MACROS_VERSION],
> XORG_MACROS_VERSION(1.8)
> XORG_DEFAULT_OPTIONS
>
> +AC_CHECK_FUNCS([asprintf])
> +
> PKG_CHECK_MODULES(RGB, xproto)
>
> AC_MSG_CHECKING([for rgb database location])
> diff --git a/showrgb.c b/showrgb.c
> index 31936ea..4796c5a 100644
> --- a/showrgb.c
> +++ b/showrgb.c
> @@ -124,9 +124,16 @@ dumprgb (const char *filename)
> int lineno = 0;
> int red, green, blue;
>
> +#ifdef HAVE_ASPRINTF
> + if (asprintf(&path, "%s.txt", filename) == -1) {
> + perror (ProgramName);
> + exit (1);
> + }
> +#else
> path = (char *)malloc(strlen(filename) + 5);
> strcpy(path, filename);
> strcat(path, ".txt");
> +#endif
Why an error check for asprintf() but not for malloc() ?
Intentional ?
re,
wh
> if (!(rgb = fopen(path, "r"))) {
> fprintf (stderr, "%s: unable to open rgb database \"%s\"\n",
More information about the xorg-devel
mailing list