summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2019-03-29 19:02:51 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2019-03-29 19:02:51 -0700
commit2d017a68e12acf2463edc9cfbdae0aea3ce477b1 (patch)
tree377cfa60a2a2a4a405b3b26e6157b03833f92c0b
parent261992d42905f209cd5bf6afcf8a7ae3aa30b3ff (diff)
Use strndup if available to avoid -Wstringop-overflow warning from gcc 9
Reported in https://gitlab.freedesktop.org/xorg/lib/libxkbfile/issues/5 Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--configure.ac1
-rw-r--r--src/xkbatom.c12
2 files changed, 10 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 86b7833..9611b8c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,7 @@ XORG_MACROS_VERSION(1.8)
XORG_DEFAULT_OPTIONS
# Checks for library functions.
+AC_CHECK_FUNCS([strndup])
AC_CHECK_FUNC(strcasecmp, [], AC_DEFINE([NEED_STRCASECMP], 1,
[Do not have 'strcasecmp'.]))
AC_CHECK_FUNC(getc_unlocked, AC_DEFINE([HAVE_UNLOCKED_STDIO], 1,
diff --git a/src/xkbatom.c b/src/xkbatom.c
index c55ee44..564cc83 100644
--- a/src/xkbatom.c
+++ b/src/xkbatom.c
@@ -103,7 +103,7 @@ static unsigned long tableLength;
static NodePtr *nodeTable;
static Atom
-_XkbMakeAtom(const char *string, unsigned len, Bool makeit)
+_XkbMakeAtom(const char *string, size_t len, Bool makeit)
{
register NodePtr *np;
unsigned i;
@@ -121,7 +121,7 @@ _XkbMakeAtom(const char *string, unsigned len, Bool makeit)
else if (fp > (*np)->fingerPrint)
np = &((*np)->right);
else { /* now start testing the strings */
- comp = strncmp(string, (*np)->string, (int) len);
+ comp = strncmp(string, (*np)->string, len);
if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string))))
np = &((*np)->left);
else if (comp > 0)
@@ -136,13 +136,19 @@ _XkbMakeAtom(const char *string, unsigned len, Bool makeit)
nd = (NodePtr) _XkbAlloc(sizeof(NodeRec));
if (!nd)
return BAD_RESOURCE;
+#ifdef HAVE_STRNDUP
+ nd->string = strndup(string, len);
+#else
nd->string = (char *) _XkbAlloc(len + 1);
+#endif
if (!nd->string) {
_XkbFree(nd);
return BAD_RESOURCE;
}
- strncpy(nd->string, string, (int) len);
+#ifndef HAVE_STRNDUP
+ strncpy(nd->string, string, len);
nd->string[len] = 0;
+#endif
if ((lastAtom + 1) >= tableLength) {
NodePtr *table;