summaryrefslogtreecommitdiff
path: root/src
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 /src
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>
Diffstat (limited to 'src')
-rw-r--r--src/xkbatom.c12
1 files changed, 9 insertions, 3 deletions
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;