diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2018-08-25 14:47:01 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2018-08-25 15:16:28 -0700 |
commit | 7f00938c6d4499d78b61feaddb4bfb6af00f6e26 (patch) | |
tree | 6752b0459903f5678bda6bfcc60c28418519bd9c | |
parent | 538ddd32790f0031357807b1b0c6c10879607209 (diff) |
Use asprintf if available, instead of malloc+strcpy+strcat
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | xcursorgen.c | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index f70d505..f62e656 100644 --- a/configure.ac +++ b/configure.ac @@ -8,6 +8,7 @@ AC_INIT([xcursorgen], [xcursorgen]) AC_CONFIG_SRCDIR([Makefile.am]) AC_CONFIG_HEADERS([config.h]) +AC_USE_SYSTEM_EXTENSIONS # Initialize Automake AM_INIT_AUTOMAKE([foreign dist-bzip2]) @@ -21,6 +22,8 @@ XORG_DEFAULT_OPTIONS # Checks for pkg-config packages PKG_CHECK_MODULES(XCURSORGEN, x11 xcursor libpng >= 1.2.0) +AC_CHECK_FUNCS([asprintf]) + AC_CONFIG_FILES([ Makefile man/Makefile]) diff --git a/xcursorgen.c b/xcursorgen.c index ba9d85c..2aa116c 100644 --- a/xcursorgen.c +++ b/xcursorgen.c @@ -210,6 +210,15 @@ load_image (struct flist *list, const char *prefix) if (prefix) { +#ifdef HAVE_ASPRINTF + if (asprintf(&file, "%s/%s", prefix, list->pngfile) == -1) + { + fprintf (stderr, "%s: asprintf() failed: %s\n", + ProgramName, strerror(errno)); + png_destroy_read_struct (&png, &info, NULL); + return NULL; + } +#else file = malloc (strlen (prefix) + 1 + strlen (list->pngfile) + 1); if (file == NULL) { @@ -221,6 +230,7 @@ load_image (struct flist *list, const char *prefix) strcpy (file, prefix); strcat (file, "/"); strcat (file, list->pngfile); +#endif } else file = list->pngfile; |