diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-10-19 21:49:57 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-11-03 10:48:07 -0800 |
commit | 8c75f6e1c117f3d05f0bc7bed34f0e7e933f3b9a (patch) | |
tree | 078f176a961776513414a1b2ae5a9a282217927e | |
parent | d5de178fe9c20351ff400ff616ffbfe05471cdcc (diff) | |
download | xorg-driver-xf86-input-mouse-8c75f6e1c117f3d05f0bc7bed34f0e7e933f3b9a.tar.gz |
Use asprintf (or Xprintf on old servers) instead of strdup+sprintf
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | src/mouse.c | 57 |
2 files changed, 43 insertions, 17 deletions
diff --git a/configure.ac b/configure.ac index ee6a345..bd782a5 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,9 @@ XORG_MACROS_VERSION(1.8) XORG_DEFAULT_OPTIONS XORG_WITH_LINT +# Checks for library functions +AC_CHECK_FUNCS([asprintf]) + # Obtain compiler/linker options from server and required extensions PKG_CHECK_MODULES(XORG, [xorg-server >= 1.7] xproto inputproto) diff --git a/src/mouse.c b/src/mouse.c index f60d6c2..2da2b4d 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -74,6 +74,13 @@ #include "mousePriv.h" #include "mipointer.h" +/* Xorg >= 1.10 provides an asprintf() implementation even if libc doesn't */ +#include "xorgVersion.h" +#if defined(HAVE_ASPRINTF) || \ + (XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,10,0,0,0)) +# define USE_ASPRINTF +#endif + enum { /* number of bits in mapped nibble */ NIB_BITS=4, @@ -441,20 +448,27 @@ MouseCommonOptions(InputInfoPtr pInfo) } else if (sscanf(s, "%d %d %d %d", &b1, &b2, &b3, &b4) >= 2 && b1 > 0 && b1 <= MSE_MAXBUTTONS && b2 > 0 && b2 <= MSE_MAXBUTTONS) { - msg = xstrdup("buttons XX and YY"); - if (msg) - sprintf(msg, "buttons %d and %d", b1, b2); pMse->negativeZ = 1 << (b1-1); pMse->positiveZ = 1 << (b2-1); if (b3 > 0 && b3 <= MSE_MAXBUTTONS && b4 > 0 && b4 <= MSE_MAXBUTTONS) { - if (msg) - free(msg); - msg = xstrdup("buttons XX, YY, ZZ and WW"); - if (msg) - sprintf(msg, "buttons %d, %d, %d and %d", b1, b2, b3, b4); pMse->negativeW = 1 << (b3-1); pMse->positiveW = 1 << (b4-1); +#ifdef USE_ASPRINTF + if (asprintf(&msg, "buttons %d, %d, %d and %d", + b1, b2, b3, b4) == -1) + msg = NULL; +#else + msg = Xprintf("buttons %d, %d, %d and %d", b1, b2, b3, b4); +#endif + } + else { +#ifdef USE_ASPRINTF + if (asprintf(&msg, "buttons %d and %d", b1, b2) == -1) + msg = NULL; +#else + msg = Xprintf("buttons %d and %d", b1, b2); +#endif } if (b1 > pMse->buttons) pMse->buttons = b1; if (b2 > pMse->buttons) pMse->buttons = b2; @@ -509,9 +523,12 @@ MouseCommonOptions(InputInfoPtr pInfo) if ((sscanf(s, "%d %d", &b1, &b2) == 2) && b1 > 0 && b1 <= MSE_MAXBUTTONS && b2 > 0 && b2 <= MSE_MAXBUTTONS) { - msg = xstrdup("buttons XX and YY"); - if (msg) - sprintf(msg, "buttons %d and %d", b1, b2); +#ifdef USE_ASPRINTF + if (asprintf(&msg, "buttons %d and %d", b1, b2) == -1) + msg = NULL; +#else + msg = Xprintf("buttons %d and %d", b1, b2); +#endif pMse->negativeX = b1; pMse->positiveX = b2; if (b1 > pMse->buttons) pMse->buttons = b1; @@ -534,9 +551,12 @@ MouseCommonOptions(InputInfoPtr pInfo) if ((sscanf(s, "%d %d", &b1, &b2) == 2) && b1 > 0 && b1 <= MSE_MAXBUTTONS && b2 > 0 && b2 <= MSE_MAXBUTTONS) { - msg = xstrdup("buttons XX and YY"); - if (msg) - sprintf(msg, "buttons %d and %d", b1, b2); +#ifdef USE_ASPRINTF + if (asprintf(&msg, "buttons %d and %d", b1, b2) == -1) + msg = NULL; +#else + msg = Xprintf("buttons %d and %d", b1, b2); +#endif pMse->negativeY = b1; pMse->positiveY = b2; if (b1 > pMse->buttons) pMse->buttons = b1; @@ -606,9 +626,12 @@ MouseCommonOptions(InputInfoPtr pInfo) if ((sscanf(s, "%d %d", &b1, &b2) == 2) && (b1 > 0) && (b1 <= MSE_MAXBUTTONS) && (b2 > 0) && (b2 <= MSE_MAXBUTTONS)) { - msg = xstrdup("buttons XX and YY"); - if (msg) - sprintf(msg, "buttons %d and %d", b1, b2); +#ifdef USE_ASPRINTF + if (asprintf(&msg, "buttons %d and %d", b1, b2) == -1) + msg = NULL; +#else + msg = Xprintf("buttons %d and %d", b1, b2); +#endif pMse->doubleClickTargetButton = b1; pMse->doubleClickTargetButtonMask = 1 << (b1 - 1); pMse->doubleClickSourceButtonMask = 1 << (b2 - 1); |