aboutsummaryrefslogtreecommitdiff
path: root/nx-X11
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-04-27 14:10:57 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-04-27 14:10:57 +0200
commit91d9218c0cc659f40918af6ac6c035c6c48d2c6d (patch)
tree79054df1730d4723658b02cec311bc8ba7655662 /nx-X11
parenta502149a844736dcc7f7dedd7c63229c74a448ee (diff)
parent4875a15ca61358a1c95b156b2279fce092451278 (diff)
downloadnx-libs-91d9218c0cc659f40918af6ac6c035c6c48d2c6d.tar.gz
nx-libs-91d9218c0cc659f40918af6ac6c035c6c48d2c6d.tar.bz2
nx-libs-91d9218c0cc659f40918af6ac6c035c6c48d2c6d.zip
Merge branch 'uli42-pr/update_libX11_2022' into 3.6.x
Attributes GH PR #1037: https://github.com/ArcticaProject/nx-libs/pull/1037
Diffstat (limited to 'nx-X11')
-rw-r--r--nx-X11/lib/configure.ac112
-rw-r--r--nx-X11/lib/include/X11/ImUtil.h12
-rw-r--r--nx-X11/lib/include/X11/XKBlib.h2
-rw-r--r--nx-X11/lib/include/X11/Xlib.h16
-rw-r--r--nx-X11/lib/include/X11/Xlibint.h29
-rw-r--r--nx-X11/lib/m4/ax_gcc_builtin.m4176
-rw-r--r--nx-X11/lib/modules/im/ximcp/imCallbk.c4
-rw-r--r--nx-X11/lib/modules/im/ximcp/imDefIc.c8
-rw-r--r--nx-X11/lib/modules/im/ximcp/imDefIm.c37
-rw-r--r--nx-X11/lib/modules/im/ximcp/imInsClbk.c11
-rw-r--r--nx-X11/lib/modules/im/ximcp/imLcFlt.c14
-rw-r--r--nx-X11/lib/modules/im/ximcp/imLcPrs.c6
-rw-r--r--nx-X11/lib/modules/im/ximcp/imRmAttr.c52
-rw-r--r--nx-X11/lib/modules/im/ximcp/imThaiFlt.c4
-rw-r--r--nx-X11/lib/modules/im/ximcp/imTrX.c1
-rw-r--r--nx-X11/lib/modules/im/ximcp/imTrans.c1
-rw-r--r--nx-X11/lib/modules/lc/gen/lcGenConv.c10
-rw-r--r--nx-X11/lib/modules/om/generic/omGeneric.c13
-rw-r--r--nx-X11/lib/modules/om/generic/omTextEsc.c6
-rw-r--r--nx-X11/lib/src/Context.c5
-rw-r--r--nx-X11/lib/src/CopyCmap.c5
-rw-r--r--nx-X11/lib/src/CrCmap.c6
-rw-r--r--nx-X11/lib/src/Depths.c3
-rw-r--r--nx-X11/lib/src/ErrDes.c4
-rw-r--r--nx-X11/lib/src/ErrHndlr.c25
-rw-r--r--nx-X11/lib/src/FSWrap.c9
-rw-r--r--nx-X11/lib/src/FetchName.c4
-rw-r--r--nx-X11/lib/src/Font.c28
-rw-r--r--nx-X11/lib/src/FontInfo.c18
-rw-r--r--nx-X11/lib/src/FontNames.c8
-rw-r--r--nx-X11/lib/src/FreeCmap.c6
-rw-r--r--nx-X11/lib/src/GetAtomNm.c19
-rw-r--r--nx-X11/lib/src/GetColor.c6
-rw-r--r--nx-X11/lib/src/GetDflt.c6
-rw-r--r--nx-X11/lib/src/GetFPath.c3
-rw-r--r--nx-X11/lib/src/GetHints.c4
-rw-r--r--nx-X11/lib/src/GetImage.c15
-rw-r--r--nx-X11/lib/src/GetMoEv.c3
-rw-r--r--nx-X11/lib/src/GetPntMap.c4
-rw-r--r--nx-X11/lib/src/GetRGBCMap.c3
-rw-r--r--nx-X11/lib/src/GetStCmap.c3
-rw-r--r--nx-X11/lib/src/GetWAttrs.c15
-rw-r--r--nx-X11/lib/src/Host.c6
-rw-r--r--nx-X11/lib/src/ImUtil.c8
-rw-r--r--nx-X11/lib/src/IntAtom.c15
-rw-r--r--nx-X11/lib/src/KeyBind.c16
-rw-r--r--nx-X11/lib/src/KeysymStr.c2
-rw-r--r--nx-X11/lib/src/LiICmaps.c4
-rw-r--r--nx-X11/lib/src/LiProps.c4
-rw-r--r--nx-X11/lib/src/ListExt.c3
-rw-r--r--nx-X11/lib/src/LoadFont.c6
-rw-r--r--nx-X11/lib/src/LookupCol.c10
-rw-r--r--nx-X11/lib/src/Makefile.am1
-rw-r--r--nx-X11/lib/src/ModMap.c3
-rw-r--r--nx-X11/lib/src/OpenDis.c45
-rw-r--r--nx-X11/lib/src/ParseCol.c9
-rw-r--r--nx-X11/lib/src/PixFormats.c3
-rw-r--r--nx-X11/lib/src/PolyReg.c5
-rw-r--r--nx-X11/lib/src/PolyTxt.c2
-rw-r--r--nx-X11/lib/src/PutBEvent.c4
-rw-r--r--nx-X11/lib/src/PutImage.c11
-rw-r--r--nx-X11/lib/src/QuColors.c5
-rw-r--r--nx-X11/lib/src/QuExt.c7
-rw-r--r--nx-X11/lib/src/QuTree.c4
-rw-r--r--nx-X11/lib/src/Quarks.c31
-rw-r--r--nx-X11/lib/src/RdBitF.c6
-rw-r--r--nx-X11/lib/src/Region.c13
-rw-r--r--nx-X11/lib/src/RegstFlt.c1
-rw-r--r--nx-X11/lib/src/SetCRects.c2
-rw-r--r--nx-X11/lib/src/SetFPath.c12
-rw-r--r--nx-X11/lib/src/SetHints.c16
-rw-r--r--nx-X11/lib/src/SetLocale.c2
-rw-r--r--nx-X11/lib/src/StNColor.c5
-rw-r--r--nx-X11/lib/src/StName.c11
-rw-r--r--nx-X11/lib/src/Text.c2
-rw-r--r--nx-X11/lib/src/TextToStr.c4
-rw-r--r--nx-X11/lib/src/VisUtil.c8
-rw-r--r--nx-X11/lib/src/WMProps.c4
-rw-r--r--nx-X11/lib/src/Window.c6
-rw-r--r--nx-X11/lib/src/WrBitF.c3
-rw-r--r--nx-X11/lib/src/XlibAsync.c18
-rw-r--r--nx-X11/lib/src/XlibInt.c109
-rw-r--r--nx-X11/lib/src/Xrm.c18
-rw-r--r--nx-X11/lib/src/globals.c2
-rw-r--r--nx-X11/lib/src/imConv.c4
-rw-r--r--nx-X11/lib/src/locking.c26
-rw-r--r--nx-X11/lib/src/locking.h12
-rw-r--r--nx-X11/lib/src/reallocarray.c43
-rw-r--r--nx-X11/lib/src/reallocarray.h44
-rw-r--r--nx-X11/lib/src/util/makekeys.c35
-rw-r--r--nx-X11/lib/src/util/mkks.sh5
-rw-r--r--nx-X11/lib/src/xcms/CvCols.c5
-rw-r--r--nx-X11/lib/src/xcms/HVCGcVC.c2
-rw-r--r--nx-X11/lib/src/xcms/HVCMxC.c2
-rw-r--r--nx-X11/lib/src/xcms/LRGB.c8
-rw-r--r--nx-X11/lib/src/xcms/Lab.c2
-rw-r--r--nx-X11/lib/src/xcms/Luv.c2
-rw-r--r--nx-X11/lib/src/xcms/StCols.c5
-rw-r--r--nx-X11/lib/src/xcms/cmsAllNCol.c2
-rw-r--r--nx-X11/lib/src/xcms/cmsColNm.c17
-rw-r--r--nx-X11/lib/src/xcms/cmsInt.c9
-rw-r--r--nx-X11/lib/src/xcms/cmsLkCol.c2
-rw-r--r--nx-X11/lib/src/xcms/xyY.c2
-rw-r--r--nx-X11/lib/src/xkb/XKB.c2
-rw-r--r--nx-X11/lib/src/xkb/XKBAlloc.c65
-rw-r--r--nx-X11/lib/src/xkb/XKBBind.c22
-rw-r--r--nx-X11/lib/src/xkb/XKBExtDev.c2
-rw-r--r--nx-X11/lib/src/xkb/XKBGAlloc.c6
-rw-r--r--nx-X11/lib/src/xkb/XKBGetByName.c12
-rw-r--r--nx-X11/lib/src/xkb/XKBGetMap.c21
-rw-r--r--nx-X11/lib/src/xkb/XKBList.c14
-rw-r--r--nx-X11/lib/src/xkb/XKBMAlloc.c137
-rw-r--r--nx-X11/lib/src/xkb/XKBMisc.c14
-rw-r--r--nx-X11/lib/src/xkb/XKBNames.c10
-rw-r--r--nx-X11/lib/src/xkb/XKBRdBuf.c2
-rw-r--r--nx-X11/lib/src/xkb/XKBSetGeom.c18
-rw-r--r--nx-X11/lib/src/xkb/XKBlibint.h22
-rw-r--r--nx-X11/lib/src/xlibi18n/ICWrap.c5
-rw-r--r--nx-X11/lib/src/xlibi18n/XimProto.h4
-rw-r--r--nx-X11/lib/src/xlibi18n/XlcPublic.h2
-rw-r--r--nx-X11/lib/src/xlibi18n/Xlcint.h4
-rw-r--r--nx-X11/lib/src/xlibi18n/imKStoUCS.c6
-rw-r--r--nx-X11/lib/src/xlibi18n/lcCT.c22
-rw-r--r--nx-X11/lib/src/xlibi18n/lcCharSet.c8
-rw-r--r--nx-X11/lib/src/xlibi18n/lcConv.c25
-rw-r--r--nx-X11/lib/src/xlibi18n/lcDB.c53
-rw-r--r--nx-X11/lib/src/xlibi18n/lcFile.c35
-rw-r--r--nx-X11/lib/src/xlibi18n/lcGeneric.c37
-rw-r--r--nx-X11/lib/src/xlibi18n/lcPrTxt.c11
-rw-r--r--nx-X11/lib/src/xlibi18n/lcPublic.c3
-rw-r--r--nx-X11/lib/src/xlibi18n/lcStd.c56
-rw-r--r--nx-X11/lib/src/xlibi18n/lcTxtPr.c12
-rw-r--r--nx-X11/lib/src/xlibi18n/lcUTF8.c50
-rw-r--r--nx-X11/lib/src/xlibi18n/lcUtil.c10
-rw-r--r--nx-X11/lib/src/xlibi18n/lcWrap.c52
135 files changed, 1318 insertions, 813 deletions
diff --git a/nx-X11/lib/configure.ac b/nx-X11/lib/configure.ac
index c616dab57..c8001eda3 100644
--- a/nx-X11/lib/configure.ac
+++ b/nx-X11/lib/configure.ac
@@ -1,22 +1,20 @@
# Initialize Autoconf
AC_PREREQ([2.60])
-AC_INIT([libNX_X11], [1.6.7],
+AC_INIT([libNX_X11], [1.7.3.1],
[https://github.com/ArcticaProject/nx-libs/issues], [libNX_X11])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_SRCDIR([Makefile.am])
AC_CONFIG_HEADERS([src/config.h include/X11/XlibConf.h])
AC_CONFIG_MACRO_DIR([m4])
-
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
-
# Set common system defines for POSIX extensions, such as _GNU_SOURCE
# Must be called before any macros that run the compiler (like AC_PROG_LIBTOOL)
# to avoid autoconf errors.
AC_USE_SYSTEM_EXTENSIONS
# Initialize Automake
-AM_INIT_AUTOMAKE([foreign dist-bzip2])
+AM_INIT_AUTOMAKE([foreign dist-xz])
# Initialize libtool
AC_PROG_LIBTOOL
@@ -37,8 +35,47 @@ NX_DEFAULT_OPTIONS
# Required when PKG_CHECK_MODULES called within an if statement
PKG_PROG_PKG_CONFIG
+if test x"$CC_FOR_BUILD" = x; then
+ if test x"$cross_compiling" = xyes; then
+ AC_CHECK_PROGS(CC_FOR_BUILD, gcc cc)
+ else
+ CC_FOR_BUILD="$CC"
+ fi
+fi
+AC_SUBST([CC_FOR_BUILD])
+
+if test x"$CPPFLAGS_FOR_BUILD" = x; then
+ if test ! x"$cross_compiling" = xyes; then
+ CPPFLAGS_FOR_BUILD=${CPPFLAGS}
+ fi
+fi
+AC_SUBST(CPPFLAGS_FOR_BUILD)
+
+if test x"$CFLAGS_FOR_BUILD" = x; then
+ if test ! x"$cross_compiling" = xyes; then
+ CFLAGS_FOR_BUILD=${CFLAGS}
+ fi
+fi
+AC_SUBST(CFLAGS_FOR_BUILD)
+
+if test x"$LDFLAGS_FOR_BUILD" = x; then
+ if test ! x"$cross_compiling" = xyes; then
+ LDFLAGS_FOR_BUILD=${LDFLAGS}
+ fi
+fi
+AC_SUBST(LDFLAGS_FOR_BUILD)
+
+if test x"$EXEEXT_FOR_BUILD" = x; then
+ if test x"$cross_compiling" = xno; then
+ EXEEXT_FOR_BUILD=${EXEEXT}
+ fi
+ # If cross-compiling and not provided, assume EXEEXT_FOR_BUILD is empty
+fi
+AC_SUBST([EXEEXT_FOR_BUILD])
+
# Checks for pkg-config packages
+# Always required
X11_REQUIRES='nx-xproto nx-xextproto nx-xtrans'
X11_EXTRA_DEPS=""
@@ -62,12 +99,16 @@ AC_SUBST(AR_FLAGS, [cr])
# Issue an error if nx-xtrans.m4 was not found and NX_XTRANS_CONNECTION_FLAGS macro
# was not expanded, since libNX_X11 with no transport types is rather useless.
+#
+# If you're seeing an error here, be sure you installed the nx-xtrans module
+# first and if it's not in the default location, that you set the ACLOCAL
+# environment variable to find it, such as:
+# ACLOCAL="aclocal -I ${PREFIX}/share/aclocal"
m4_pattern_forbid([^NX_XTRANS_CONNECTION_FLAGS$])
# Transport selection macro from nx-xtrans.m4
NX_XTRANS_CONNECTION_FLAGS
-
# Secure RPC detection macro from xtrans.m4
NX_XTRANS_SECURE_RPC_FLAGS
@@ -93,7 +134,7 @@ if test "x$ac_cv_search_dlopen" = xno; then
AC_SEARCH_LIBS(shl_load,[dld])
if test "x$ac_cv_search_shl_load" != xno; then
AC_DEFINE(HAVE_SHL_LOAD,1,
- [Use shl_load to load shared libraries])
+ [Use shl_load to load shared libraries])
AC_CHECK_HEADERS([dl.h])
fi
else
@@ -109,27 +150,27 @@ AC_MSG_RESULT($HAVE_LOADABLE_MODULES)
AC_MSG_CHECKING([if loadable Xcursor library support should be enabled])
AC_ARG_ENABLE(loadable-xcursor,
- AS_HELP_STRING([--disable-loadable-xcursor],
- [Controls loadable xcursor library support]),
- [XLIB_LOADABLE_XCURSOR=$enableval],
- [XLIB_LOADABLE_XCURSOR=$HAVE_LOADABLE_MODULES])
+ AS_HELP_STRING([--disable-loadable-xcursor],
+ [Controls loadable xcursor library support]),
+ [XLIB_LOADABLE_XCURSOR=$enableval],
+ [XLIB_LOADABLE_XCURSOR=$HAVE_LOADABLE_MODULES])
if test x$XLIB_LOADABLE_XCURSOR = xyes; then
AC_DEFINE(USE_DYNAMIC_XCURSOR,1,
- [Use the X cursor library to load cursors])
+ [Use the X cursor library to load cursors])
fi
AC_MSG_RESULT($XLIB_LOADABLE_XCURSOR)
# Checks for header files.
-AC_CHECK_HEADERS([sys/select.h])
+AC_CHECK_HEADERS([sys/filio.h sys/select.h sys/ioctl.h sys/socket.h])
# Checks for typedefs, structures, and compiler characteristics.
+AX_GCC_BUILTIN([__builtin_popcountl])
# Checks for library functions.
AC_CHECK_FUNCS([strtol seteuid])
-
+AC_REPLACE_FUNCS([reallocarray])
# Used in lcFile.c (see also --enable-xlocaledir settings below)
XLOCALEDIR_IS_SAFE="no"
-
AC_CHECK_DECL([issetugid])
AC_CHECK_FUNC([issetugid])
if test "$ac_cv_have_decl_issetugid" = yes && test "$ac_cv_func_issetugid" = yes; then
@@ -137,7 +178,7 @@ if test "$ac_cv_have_decl_issetugid" = yes && test "$ac_cv_func_issetugid" = yes
AC_DEFINE(HASSETUGID,1,[Has issetugid() function])
fi
AC_CHECK_FUNC([getresuid], [XLOCALEDIR_IS_SAFE="yes"]
- AC_DEFINE(HASGETRESUID,1,[Has getresuid() & getresgid() functions]))
+ AC_DEFINE(HASGETRESUID,1,[Has getresuid() & getresgid() functions]))
# Used in Font.c
AC_CHECK_FUNC([shmat], AC_DEFINE(HAS_SHM,1,[Has shm*() functions]))
@@ -156,13 +197,13 @@ AC_CHECK_LIB(c, getpwuid_r, [mtsafeapi="yes"], [mtsafeapi="no"])
case x$xthreads in
xyes)
AC_DEFINE(XTHREADS,1,[Whether libNX_X11 is compiled with thread support])
- if test x$mtsafeapi = xyes
- then
+ if test x$mtsafeapi = xyes
+ then
AC_DEFINE(XUSE_MTSAFE_API,1,[Whether libNX_X11 needs to use MT safe API's])
- fi
- ;;
+ fi
+ ;;
*)
- ;;
+ ;;
esac
AC_CHECK_LIB(c, pthread_self, [thrstubs="no"], [thrstubs="yes"])
@@ -174,15 +215,15 @@ if test x$xthreads = xyes ; then
linux*|gnu*|k*bsd*-gnu)
XTHREADLIB=-lpthread ;;
netbsd*)
- XTHREAD_CFLAGS="-D_POSIX_THREAD_SAFE_FUNCTIONS"
- XTHREADLIB="-lpthread" ;;
+ XTHREAD_CFLAGS="-D_POSIX_THREAD_SAFE_FUNCTIONS"
+ XTHREADLIB="-lpthread" ;;
freebsd*)
XTHREAD_CFLAGS="-D_THREAD_SAFE"
XTHREADLIB="-pthread" ;;
dragonfly*|openbsd*)
XTHREADLIB="-pthread" ;;
solaris*)
- XTHREAD_CFLAGS="-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS" ;;
+ XTHREAD_CFLAGS="-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS" ;;
esac
fi
AC_SUBST(XTHREADLIB)
@@ -225,7 +266,7 @@ AC_ARG_WITH([keysymdefdir],
[KEYSYMDEFDIR=`pwd`/../include])
if test ! -d "$KEYSYMDEFDIR"; then
- AC_MSG_ERROR([$KEYSYMDEFDIR doesn't exist or isn't a directory])
+ AC_MSG_ERROR([$KEYSYMDEFDIR doesn't exist or isn't a directory])
fi
FILES="keysymdef.h XF86keysym.h Sunkeysym.h DECkeysym.h HPkeysym.h"
@@ -233,7 +274,7 @@ for i in $FILES; do
if test -f "$KEYSYMDEFDIR/$i"; then
KEYSYMDEFS="$KEYSYMDEFS $KEYSYMDEFDIR/$i"
elif test "x$i" = "xkeysymdef.h"; then
- AC_MSG_ERROR([Cannot find keysymdef.h])
+ AC_MSG_ERROR([Cannot find keysymdef.h])
fi
done
AC_MSG_RESULT([$KEYSYMDEFS])
@@ -245,7 +286,7 @@ AC_ARG_ENABLE(xcms,
[XCMS=$enableval],[XCMS=yes])
AM_CONDITIONAL(XCMS, [test x$XCMS = xyes ])
if test x"$XCMS" = "xyes"; then
- AC_DEFINE(XCMS,1,[Include support for XCMS])
+ AC_DEFINE(XCMS,1,[Include support for XCMS])
fi
AC_ARG_ENABLE(xlocale,
@@ -255,27 +296,26 @@ AC_ARG_ENABLE(xlocale,
AM_CONDITIONAL(XLOCALE, [ test x$XLOCALE = xyes ])
if test x"$XLOCALE" = "xyes"; then
- AC_DEFINE(XLOCALE,1,[support for X Locales])
+ AC_DEFINE(XLOCALE,1,[support for X Locales])
fi
-
# This disables XLOCALEDIR. Set it if you're using BuildLoadableXlibI18n,
# don't have either issetugid() or getresuid(), and you need to protect
# clients that are setgid or setuid to an id other than 0.
AC_MSG_CHECKING([if XLOCALEDIR support should be enabled])
AC_ARG_ENABLE(xlocaledir,
- AS_HELP_STRING([--enable-xlocaledir],
- [Enable XLOCALEDIR environment variable support]),
- [ENABLE_XLOCALEDIR=$enableval],[ENABLE_XLOCALEDIR=$XLOCALEDIR_IS_SAFE])
+ AS_HELP_STRING([--enable-xlocaledir],
+ [Enable XLOCALEDIR environment variable support]),
+ [ENABLE_XLOCALEDIR=$enableval],[ENABLE_XLOCALEDIR=$XLOCALEDIR_IS_SAFE])
if test "x$ENABLE_XLOCALEDIR" = "xno"; then
- AC_DEFINE(NO_XLOCALEDIR,1,[Disable XLOCALEDIR environment variable])
+ AC_DEFINE(NO_XLOCALEDIR,1,[Disable XLOCALEDIR environment variable])
fi
AC_MSG_RESULT($ENABLE_XLOCALEDIR)
AC_ARG_ENABLE(xf86bigfont,
- AS_HELP_STRING([--disable-xf86bigfont],
- [Disable XF86BigFont extension support]),
- [XF86BIGFONT=$enableval],[XF86BIGFONT="yes"])
+ AS_HELP_STRING([--disable-xf86bigfont],
+ [Disable XF86BigFont extension support]),
+ [XF86BIGFONT=$enableval],[XF86BIGFONT="yes"])
if test "x$XF86BIGFONT" = "xyes"; then
# FIXME: Skip check for proto headers for now... Requires .pc files for all the proto
# header packages we have. Keeping that in mind for later...
@@ -307,7 +347,7 @@ AC_ARG_ENABLE(composecache,
[Disable compose table cache support]),
[COMPOSECACHE=$enableval],[COMPOSECACHE=$composecache_default])
if test x"$COMPOSECACHE" = "xyes"; then
- AC_DEFINE(COMPOSECACHE,1,[Include compose table cache support])
+ AC_DEFINE(COMPOSECACHE,1,[Include compose table cache support])
fi
X11_DATADIR="${datadir}/nx/X11"
diff --git a/nx-X11/lib/include/X11/ImUtil.h b/nx-X11/lib/include/X11/ImUtil.h
index a8b95eead..c0aface46 100644
--- a/nx-X11/lib/include/X11/ImUtil.h
+++ b/nx-X11/lib/include/X11/ImUtil.h
@@ -16,16 +16,16 @@ _XGetBitsPerPixel(
extern int
_XSetImage(
XImage *srcimg,
- register XImage *dstimg,
- register int x,
- register int y);
+ XImage *dstimg,
+ int x,
+ int y);
extern int
_XReverse_Bytes(
- register unsigned char *bpt,
- register int nb);
+ unsigned char *bpt,
+ int nb);
extern void
_XInitImageFuncPtrs(
- register XImage *image);
+ XImage *image);
#endif /* !defined(_X11_IMUTIL_H_) && !defined(_IM_UTIL_H_) */
diff --git a/nx-X11/lib/include/X11/XKBlib.h b/nx-X11/lib/include/X11/XKBlib.h
index dd2841e9a..5d46a4820 100644
--- a/nx-X11/lib/include/X11/XKBlib.h
+++ b/nx-X11/lib/include/X11/XKBlib.h
@@ -397,7 +397,7 @@ extern Bool XkbTranslateKeyCode(
extern int XkbTranslateKeySym(
Display * /* dpy */,
- register KeySym * /* sym_return */,
+ KeySym * /* sym_return */,
unsigned int /* modifiers */,
char * /* buffer */,
int /* nbytes */,
diff --git a/nx-X11/lib/include/X11/Xlib.h b/nx-X11/lib/include/X11/Xlib.h
index 362fdb69e..5f3a407f9 100644
--- a/nx-X11/lib/include/X11/Xlib.h
+++ b/nx-X11/lib/include/X11/Xlib.h
@@ -292,7 +292,7 @@ typedef struct {
int bit_gravity; /* one of bit gravity values */
int win_gravity; /* one of the window gravity values */
int backing_store; /* NotUseful, WhenMapped, Always */
- unsigned long backing_planes;/* planes to be preseved if possible */
+ unsigned long backing_planes;/* planes to be preserved if possible */
unsigned long backing_pixel;/* value to use in restoring planes */
Bool save_under; /* should bits under be saved? (popups) */
long event_mask; /* set of events that should be saved */
@@ -364,9 +364,9 @@ typedef struct _XImage {
int bitmap_bit_order; /* LSBFirst, MSBFirst */
int bitmap_pad; /* 8, 16, 32 either XY or ZPixmap */
int depth; /* depth of image */
- int bytes_per_line; /* accelarator to next line */
+ int bytes_per_line; /* accelerator to next line */
int bits_per_pixel; /* bits per pixel (ZPixmap) */
- unsigned long red_mask; /* bits in z arrangment */
+ unsigned long red_mask; /* bits in z arrangement */
unsigned long green_mask;
unsigned long blue_mask;
XPointer obdata; /* hook for the object routines to hang on */
@@ -1858,6 +1858,16 @@ extern XIOErrorHandler XSetIOErrorHandler (
XIOErrorHandler /* handler */
);
+typedef void (*XIOErrorExitHandler) ( /* WARNING, this type not in Xlib spec */
+ Display*, /* display */
+ void* /* user_data */
+);
+
+extern void XSetIOErrorExitHandler (
+ Display*, /* display */
+ XIOErrorExitHandler, /* handler */
+ void* /* user_data */
+);
extern XPixmapFormatValues *XListPixmapFormats(
Display* /* display */,
diff --git a/nx-X11/lib/include/X11/Xlibint.h b/nx-X11/lib/include/X11/Xlibint.h
index ce20b9a3d..e5b97e3a5 100644
--- a/nx-X11/lib/include/X11/Xlibint.h
+++ b/nx-X11/lib/include/X11/Xlibint.h
@@ -236,6 +236,11 @@ struct _XDisplay
unsigned long last_request_read_upper32bit;
unsigned long request_upper32bit;
#endif
+
+ struct _XErrorThreadInfo *error_threads;
+
+ XIOErrorExitHandler exit_handler;
+ void *exit_handler_data;
};
#define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
@@ -475,15 +480,15 @@ extern LockInfoPtr _Xglobal_lock;
*/
#if defined(MALLOC_0_RETURNS_NULL) || defined(__clang_analyzer__)
-# define Xmalloc(size) malloc(((size) == 0 ? 1 : (size)))
-# define Xrealloc(ptr, size) realloc((ptr), ((size) == 0 ? 1 : (size)))
-# define Xcalloc(nelem, elsize) calloc(((nelem) == 0 ? 1 : (nelem)), (elsize))
+# define Xmalloc(size) malloc((size_t)((size) == 0 ? 1 : (size)))
+# define Xrealloc(ptr, size) realloc((ptr), (size_t)((size) == 0 ? 1 : (size)))
+# define Xcalloc(nelem, elsize) calloc((size_t)((nelem) == 0 ? 1 : (nelem)), (size_t)(elsize))
#else
-# define Xmalloc(size) malloc((size))
-# define Xrealloc(ptr, size) realloc((ptr), (size))
-# define Xcalloc(nelem, elsize) calloc((nelem), (elsize))
+# define Xmalloc(size) malloc((size_t)(size))
+# define Xrealloc(ptr, size) realloc((ptr), (size_t)(size))
+# define Xcalloc(nelem, elsize) calloc((size_t)(nelem), (size_t)(elsize))
#endif
@@ -581,7 +586,7 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len);
bytes after the request. "n" must be a multiple of 4! */
#define GetReqExtra(name, n, req) \
- GetReqSized(name, SIZEOF(x##name##Req) + n, req)
+ GetReqSized(name, SIZEOF(x##name##Req) + n, req)
/*
* GetResReq is for those requests that have a resource ID
@@ -591,7 +596,7 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len);
#define GetResReq(name, rid, req) \
req = (xResourceReq *) _XGetRequest(dpy, X_##name, SIZEOF(xResourceReq)); \
- req->id = (rid)
+ if (req) req->id = (rid)
/*
* GetEmptyReq is for those requests that have no arguments
@@ -673,7 +678,7 @@ extern void _XFlushGCCache(Display *dpy, GC gc);
#ifndef DataRoutineIsProcedure
#define Data(dpy, data, len) {\
if (dpy->bufptr + (len) <= dpy->bufmax) {\
- memcpy(dpy->bufptr, data, (int)len);\
+ memcpy(dpy->bufptr, data, (int)(len));\
dpy->bufptr += ((len) + 3) & ~3;\
} else\
_XSend(dpy, data, len);\
@@ -709,7 +714,7 @@ extern void _XFlushGCCache(Display *dpy, GC gc);
#define Data32(dpy, data, len) _XData32(dpy, (_Xconst long *)data, len)
extern int _XData32(
Display *dpy,
- _Xconst long *data,
+ _Xconst long *data,
unsigned len
);
extern void _XRead32(
@@ -1427,6 +1432,10 @@ extern int _XDefaultError(
extern int _XDefaultIOError(
Display *dpy);
+extern void _XDefaultIOErrorExit(
+ Display *dpy,
+ void *user_data);
+
extern void _XSetClipRectangles (
Display *dpy,
GC gc,
diff --git a/nx-X11/lib/m4/ax_gcc_builtin.m4 b/nx-X11/lib/m4/ax_gcc_builtin.m4
new file mode 100644
index 000000000..18e62b87a
--- /dev/null
+++ b/nx-X11/lib/m4/ax_gcc_builtin.m4
@@ -0,0 +1,176 @@
+# ===========================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_gcc_builtin.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_GCC_BUILTIN(BUILTIN)
+#
+# DESCRIPTION
+#
+# This macro checks if the compiler supports one of GCC's built-in
+# functions; many other compilers also provide those same built-ins.
+#
+# The BUILTIN parameter is the name of the built-in function.
+#
+# If BUILTIN is supported define HAVE_<BUILTIN>. Keep in mind that since
+# builtins usually start with two underscores they will be copied over
+# into the HAVE_<BUILTIN> definition (e.g. HAVE___BUILTIN_EXPECT for
+# __builtin_expect()).
+#
+# The macro caches its result in the ax_cv_have_<BUILTIN> variable (e.g.
+# ax_cv_have___builtin_expect).
+#
+# The macro currently supports the following built-in functions:
+#
+# __builtin_assume_aligned
+# __builtin_bswap16
+# __builtin_bswap32
+# __builtin_bswap64
+# __builtin_choose_expr
+# __builtin___clear_cache
+# __builtin_clrsb
+# __builtin_clrsbl
+# __builtin_clrsbll
+# __builtin_clz
+# __builtin_clzl
+# __builtin_clzll
+# __builtin_complex
+# __builtin_constant_p
+# __builtin_cpu_init
+# __builtin_cpu_is
+# __builtin_cpu_supports
+# __builtin_ctz
+# __builtin_ctzl
+# __builtin_ctzll
+# __builtin_expect
+# __builtin_ffs
+# __builtin_ffsl
+# __builtin_ffsll
+# __builtin_fpclassify
+# __builtin_huge_val
+# __builtin_huge_valf
+# __builtin_huge_vall
+# __builtin_inf
+# __builtin_infd128
+# __builtin_infd32
+# __builtin_infd64
+# __builtin_inff
+# __builtin_infl
+# __builtin_isinf_sign
+# __builtin_nan
+# __builtin_nand128
+# __builtin_nand32
+# __builtin_nand64
+# __builtin_nanf
+# __builtin_nanl
+# __builtin_nans
+# __builtin_nansf
+# __builtin_nansl
+# __builtin_object_size
+# __builtin_parity
+# __builtin_parityl
+# __builtin_parityll
+# __builtin_popcount
+# __builtin_popcountl
+# __builtin_popcountll
+# __builtin_powi
+# __builtin_powif
+# __builtin_powil
+# __builtin_prefetch
+# __builtin_trap
+# __builtin_types_compatible_p
+# __builtin_unreachable
+#
+# Unsupported built-ins will be tested with an empty parameter set and the
+# result of the check might be wrong or meaningless so use with care.
+#
+# LICENSE
+#
+# Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 7
+
+AC_DEFUN([AX_GCC_BUILTIN], [
+ AS_VAR_PUSHDEF([ac_var], [ax_cv_have_$1])
+
+ AC_CACHE_CHECK([for $1], [ac_var], [
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
+ m4_case([$1],
+ [__builtin_assume_aligned], [$1("", 0)],
+ [__builtin_bswap16], [$1(0)],
+ [__builtin_bswap32], [$1(0)],
+ [__builtin_bswap64], [$1(0)],
+ [__builtin_choose_expr], [$1(0, 0, 0)],
+ [__builtin___clear_cache], [$1("", "")],
+ [__builtin_clrsb], [$1(0)],
+ [__builtin_clrsbl], [$1(0)],
+ [__builtin_clrsbll], [$1(0)],
+ [__builtin_clz], [$1(0)],
+ [__builtin_clzl], [$1(0)],
+ [__builtin_clzll], [$1(0)],
+ [__builtin_complex], [$1(0.0, 0.0)],
+ [__builtin_constant_p], [$1(0)],
+ [__builtin_cpu_init], [$1()],
+ [__builtin_cpu_is], [$1("intel")],
+ [__builtin_cpu_supports], [$1("sse")],
+ [__builtin_ctz], [$1(0)],
+ [__builtin_ctzl], [$1(0)],
+ [__builtin_ctzll], [$1(0)],
+ [__builtin_expect], [$1(0, 0)],
+ [__builtin_ffs], [$1(0)],
+ [__builtin_ffsl], [$1(0)],
+ [__builtin_ffsll], [$1(0)],
+ [__builtin_fpclassify], [$1(0, 1, 2, 3, 4, 0.0)],
+ [__builtin_huge_val], [$1()],
+ [__builtin_huge_valf], [$1()],
+ [__builtin_huge_vall], [$1()],
+ [__builtin_inf], [$1()],
+ [__builtin_infd128], [$1()],
+ [__builtin_infd32], [$1()],
+ [__builtin_infd64], [$1()],
+ [__builtin_inff], [$1()],
+ [__builtin_infl], [$1()],
+ [__builtin_isinf_sign], [$1(0.0)],
+ [__builtin_nan], [$1("")],
+ [__builtin_nand128], [$1("")],
+ [__builtin_nand32], [$1("")],
+ [__builtin_nand64], [$1("")],
+ [__builtin_nanf], [$1("")],
+ [__builtin_nanl], [$1("")],
+ [__builtin_nans], [$1("")],
+ [__builtin_nansf], [$1("")],
+ [__builtin_nansl], [$1("")],
+ [__builtin_object_size], [$1("", 0)],
+ [__builtin_parity], [$1(0)],
+ [__builtin_parityl], [$1(0)],
+ [__builtin_parityll], [$1(0)],
+ [__builtin_popcount], [$1(0)],
+ [__builtin_popcountl], [$1(0)],
+ [__builtin_popcountll], [$1(0)],
+ [__builtin_powi], [$1(0, 0)],
+ [__builtin_powif], [$1(0, 0)],
+ [__builtin_powil], [$1(0, 0)],
+ [__builtin_prefetch], [$1("")],
+ [__builtin_trap], [$1()],
+ [__builtin_types_compatible_p], [$1(int, int)],
+ [__builtin_unreachable], [$1()],
+ [m4_warn([syntax], [Unsupported built-in $1, the test may fail])
+ $1()]
+ )
+ ])],
+ [AS_VAR_SET([ac_var], [yes])],
+ [AS_VAR_SET([ac_var], [no])])
+ ])
+
+ AS_IF([test yes = AS_VAR_GET([ac_var])],
+ [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$1), 1,
+ [Define to 1 if the system has the `$1' built-in function])], [])
+
+ AS_VAR_POPDEF([ac_var])
+])
diff --git a/nx-X11/lib/modules/im/ximcp/imCallbk.c b/nx-X11/lib/modules/im/ximcp/imCallbk.c
index ead0806c6..359d9b8ca 100644
--- a/nx-X11/lib/modules/im/ximcp/imCallbk.c
+++ b/nx-X11/lib/modules/im/ximcp/imCallbk.c
@@ -265,7 +265,7 @@ _XimGeometryCallback(Xim im,
{
XICCallback* cb = &ic->core.geometry_callback;
- /* invoke the callack
+ /* invoke the callback
*/
if (cb && cb->callback) {
(*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
@@ -728,7 +728,7 @@ _XimPreeditStateNotifyCallback( Xim im, Xic ic, char* proto, int len )
{
XICCallback *cb = &ic->core.preedit_attr.state_notify_callback;
- /* invoke the callack
+ /* invoke the callback
*/
if( cb && cb->callback ) {
XIMPreeditStateNotifyCallbackStruct cbrec;
diff --git a/nx-X11/lib/modules/im/ximcp/imDefIc.c b/nx-X11/lib/modules/im/ximcp/imDefIc.c
index 30c2d0136..d552aa9e7 100644
--- a/nx-X11/lib/modules/im/ximcp/imDefIc.c
+++ b/nx-X11/lib/modules/im/ximcp/imDefIc.c
@@ -350,7 +350,7 @@ _XimProtoGetICValues(
+ sizeof(INT16)
+ XIM_PAD(2 + buf_size);
- if (!(buf = Xmalloc(buf_size)))
+ if (!(buf = Xcalloc(buf_size, 1)))
return arg->name;
buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
@@ -708,6 +708,7 @@ _XimProtoSetICValues(
#endif /* XIM_CONNECTABLE */
_XimGetCurrentICValues(ic, &ic_values);
+ memset(tmp_buf, 0, sizeof(tmp_buf32));
buf = tmp_buf;
buf_size = XIM_HEADER_SIZE
+ sizeof(CARD16) + sizeof(CARD16) + sizeof(INT16) + sizeof(CARD16);
@@ -730,7 +731,7 @@ _XimProtoSetICValues(
buf_size += ret_len;
if (buf == tmp_buf) {
- if (!(tmp = Xmalloc(buf_size + data_len))) {
+ if (!(tmp = Xcalloc(buf_size + data_len, 1))) {
return tmp_name;
}
memcpy(tmp, buf, buf_size);
@@ -740,6 +741,7 @@ _XimProtoSetICValues(
Xfree(buf);
return tmp_name;
}
+ memset(&tmp[buf_size], 0, data_len);
buf = tmp;
}
}
@@ -867,6 +869,7 @@ _XimProtoICFree(
}
#endif /* XIM_CONNECTABLE */
+
Xfree(ic->private.proto.saved_icvalues);
ic->private.proto.saved_icvalues = NULL;
@@ -878,6 +881,7 @@ _XimProtoICFree(
Xfree(ic->core.hotkey);
ic->core.hotkey = NULL;
+
return;
}
diff --git a/nx-X11/lib/modules/im/ximcp/imDefIm.c b/nx-X11/lib/modules/im/ximcp/imDefIm.c
index 2a1ccb4ec..14da20bc4 100644
--- a/nx-X11/lib/modules/im/ximcp/imDefIm.c
+++ b/nx-X11/lib/modules/im/ximcp/imDefIm.c
@@ -62,6 +62,7 @@ PERFORMANCE OF THIS SOFTWARE.
#include "XimTrInt.h"
#include "Ximint.h"
+#include <limits.h>
int
_XimCheckDataSize(
@@ -330,9 +331,7 @@ _XimPreConnectionIM(
else
goto Error;
}
- if( (locale_name[3] = Xmalloc(llen+1)) != NULL )
- strcpy( locale_name[3], language );
- else
+ if( (locale_name[3] = strdup(language)) == NULL )
goto Error;
if((locales = XInternAtom(display, XIM_LOCALES, True)) == (Atom)None)
goto Error;
@@ -809,12 +808,16 @@ _XimOpen(
int buf_size;
int ret_code;
char *locale_name;
+ size_t locale_len;
locale_name = im->private.proto.locale_name;
- len = strlen(locale_name);
- buf_b[0] = (BYTE)len; /* length of locale name */
- (void)strcpy((char *)&buf_b[1], locale_name); /* locale name */
- len += sizeof(BYTE); /* sizeof length */
+ locale_len = strlen(locale_name);
+ if (locale_len > UCHAR_MAX)
+ return False;
+ memset(buf32, 0, sizeof(buf32));
+ buf_b[0] = (BYTE)locale_len; /* length of locale name */
+ memcpy(&buf_b[1], locale_name, locale_len); /* locale name */
+ len = (INT16)(locale_len + sizeof(BYTE)); /* sizeof length */
XIM_SET_PAD(buf_b, len); /* pad */
_XimSetHeader((XPointer)buf, XIM_OPEN, 0, &len);
@@ -871,7 +874,7 @@ _XimOpen(
_XimSetIMMode(im->private.proto.im_inner_resources,
im->private.proto.im_num_inner_resources);
- /* Transport Callbak */
+ /* Transport Callback */
_XimRegProtoIntrCallback(im, XIM_SET_EVENT_MASK, 0,
_XimSetEventMaskCallback, (XPointer)im);
_XimRegProtoIntrCallback(im, XIM_FORWARD_EVENT, 0,
@@ -1289,6 +1292,7 @@ _XimProtoSetIMValues(
#endif /* XIM_CONNECTABLE */
_XimGetCurrentIMValues(im, &im_values);
+ memset(tmp_buf, 0, sizeof(tmp_buf32));
buf = tmp_buf;
buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
data_len = BUFSIZE - buf_size;
@@ -1299,8 +1303,6 @@ _XimProtoSetIMValues(
if ((name = _XimEncodeIMATTRIBUTE(im, im->core.im_resources,
im->core.im_num_resources, arg, &arg_ret, data, data_len,
&ret_len, (XPointer)&im_values, XIM_SETIMVALUES))) {
- if (buf != tmp_buf)
- Xfree(buf);
break;
}
@@ -1311,7 +1313,7 @@ _XimProtoSetIMValues(
buf_size += ret_len;
if (buf == tmp_buf) {
- if (!(tmp = Xmalloc(buf_size + data_len))) {
+ if (!(tmp = Xcalloc(buf_size + data_len, 1))) {
return arg->name;
}
memcpy(tmp, buf, buf_size);
@@ -1321,6 +1323,7 @@ _XimProtoSetIMValues(
Xfree(buf);
return arg->name;
}
+ memset(&tmp[buf_size], 0, data_len);
buf = tmp;
}
}
@@ -1462,7 +1465,7 @@ _XimProtoGetIMValues(
+ sizeof(INT16)
+ XIM_PAD(buf_size);
- if (!(buf = Xmalloc(buf_size)))
+ if (!(buf = Xcalloc(buf_size, 1)))
return arg->name;
buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
@@ -1562,10 +1565,10 @@ _XimSetEncodingByName(
*buf = (char *)ret;
ret[0] = (BYTE)encoding_len;
- (void)strncpy((char *)&ret[1], encoding, encoding_len);
+ memcpy(&ret[1], encoding, encoding_len);
ret += (encoding_len + sizeof(BYTE));
ret[0] = (BYTE)compound_len;
- (void)strncpy((char *)&ret[1], "COMPOUND_TEXT", compound_len);
+ memcpy(&ret[1], "COMPOUND_TEXT", compound_len);
return True;
}
@@ -1724,7 +1727,7 @@ _XimEncodingNegotiation(
+ sizeof(CARD16)
+ detail_len;
- if (!(buf = Xmalloc(XIM_HEADER_SIZE + len)))
+ if (!(buf = Xcalloc(XIM_HEADER_SIZE + len, 1)))
goto free_detail_ptr;
buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
@@ -1820,6 +1823,7 @@ _XimSendSavedIMValues(
int ret_code;
_XimGetCurrentIMValues(im, &im_values);
+ memset(tmp_buf, 0, sizeof(tmp_buf32));
buf = tmp_buf;
buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
data_len = BUFSIZE - buf_size;
@@ -1842,7 +1846,7 @@ _XimSendSavedIMValues(
buf_size += ret_len;
if (buf == tmp_buf) {
- if (!(tmp = Xmalloc(buf_size + data_len))) {
+ if (!(tmp = Xcalloc(buf_size + data_len, 1))) {
return False;
}
memcpy(tmp, buf, buf_size);
@@ -1852,6 +1856,7 @@ _XimSendSavedIMValues(
Xfree(buf);
return False;
}
+ memset(&tmp[buf_size], 0, data_len);
buf = tmp;
}
}
diff --git a/nx-X11/lib/modules/im/ximcp/imInsClbk.c b/nx-X11/lib/modules/im/ximcp/imInsClbk.c
index 214e0a9af..62f157f1d 100644
--- a/nx-X11/lib/modules/im/ximcp/imInsClbk.c
+++ b/nx-X11/lib/modules/im/ximcp/imInsClbk.c
@@ -162,6 +162,7 @@ _XimRegisterIMInstantiateCallback(
{
XimInstCallback icb, tmp;
XIM xim;
+ char *modifiers = NULL;
Window root;
XWindowAttributes attr;
@@ -171,11 +172,18 @@ _XimRegisterIMInstantiateCallback(
icb = Xmalloc(sizeof(XimInstCallbackRec));
if( !icb )
return( False );
+ if (lcd->core->modifiers) {
+ modifiers = strdup(lcd->core->modifiers);
+ if (!modifiers) {
+ Xfree(icb);
+ return( False );
+ }
+ }
icb->call = icb->destroy = False;
icb->display = display;
icb->lcd = lcd;
MakeLocale( lcd, icb->name );
- icb->modifiers = lcd->core->modifiers; /* XXXXX */
+ icb->modifiers = modifiers;
icb->rdb = rdb;
icb->res_name = res_name;
icb->res_class = res_class;
@@ -258,6 +266,7 @@ _XimUnRegisterIMInstantiateCallback(
else
picb->next = icb->next;
_XCloseLC( icb->lcd );
+ XFree( icb->modifiers );
XFree( icb );
}
return( True );
diff --git a/nx-X11/lib/modules/im/ximcp/imLcFlt.c b/nx-X11/lib/modules/im/ximcp/imLcFlt.c
index 50f4c252a..0bd1e262c 100644
--- a/nx-X11/lib/modules/im/ximcp/imLcFlt.c
+++ b/nx-X11/lib/modules/im/ximcp/imLcFlt.c
@@ -47,7 +47,8 @@ _XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data)
unsigned currstate;
DefTree *b = ic->private.local.base.tree;
DTIndex t;
- Bool braille = False, anymodifier = False;
+ Bool anymodifier = False;
+ unsigned char braillePattern = 0;
if(ev->xkey.keycode == 0)
return (False);
@@ -67,10 +68,11 @@ _XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data)
}
ic->private.local.brl_pressed &= ~(1<<(keysym-XK_braille_dot_1));
if(!ic->private.local.brl_pressed && ic->private.local.brl_committing) {
- /* Commited a braille pattern, let it go through compose tree */
+ /* Committed a braille pattern, let it go through compose tree */
keysym = XK_braille_blank | ic->private.local.brl_committing;
ev->type = KeyPress;
- braille = True;
+ braillePattern = ic->private.local.brl_committing;
+ ic->private.local.brl_committing = 0;
} else {
return(True);
}
@@ -138,16 +140,16 @@ _XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data)
(ev->type == KeyRelease && !anymodifier)) {
goto emit_braille;
}
- /* Error (Sequence Unmatch occured) */
+ /* Error (Sequence Unmatch occurred) */
/* initialize internal state for next key sequence */
ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
return (ev->type == KeyPress);
}
emit_braille:
- if(braille) {
+ if(braillePattern) {
/* Braille pattern is not in compose tree, emit alone */
- ic->private.local.brl_committed = ic->private.local.brl_committing;
+ ic->private.local.brl_committed = braillePattern;
ic->private.local.composed = 0;
ev->xkey.keycode = 0;
_XPutBackEvent(d, ev);
diff --git a/nx-X11/lib/modules/im/ximcp/imLcPrs.c b/nx-X11/lib/modules/im/ximcp/imLcPrs.c
index fa992e5d3..d374d6ca8 100644
--- a/nx-X11/lib/modules/im/ximcp/imLcPrs.c
+++ b/nx-X11/lib/modules/im/ximcp/imLcPrs.c
@@ -501,7 +501,7 @@ parseline(
if ((filename = TransFileName(im, tokenbuf)) == NULL)
goto error;
infp = _XFopenFile(filename, "r");
- Xfree(filename);
+ Xfree(filename);
if (infp == NULL)
goto error;
parsestringfile(infp, im, depth);
@@ -676,8 +676,10 @@ parseline(
goto error;
b->tree = new;
b->treesize = newsize;
+ /* Re-derive top after realloc() to avoid undefined behaviour
+ (and crashes on architectures that track pointer bounds). */
if (top >= (DTIndex *) old && top < (DTIndex *) &old[oldsize])
- top = (DTIndex *) (((char *) top) + (((char *)b->tree)-(char *)old));
+ top = (DTIndex *) (((char *)new) + (((char *)top)-(char *)old));
}
p = &b->tree[b->treeused];
p->keysym = buf[i].keysym;
diff --git a/nx-X11/lib/modules/im/ximcp/imRmAttr.c b/nx-X11/lib/modules/im/ximcp/imRmAttr.c
index 9d4e46258..709e64ab5 100644
--- a/nx-X11/lib/modules/im/ximcp/imRmAttr.c
+++ b/nx-X11/lib/modules/im/ximcp/imRmAttr.c
@@ -29,6 +29,8 @@ PERFORMANCE OF THIS SOFTWARE.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
+
#include "Xlibint.h"
#include "Xlcint.h"
#include "Ximint.h"
@@ -214,7 +216,7 @@ _XimAttributeToValue(
Xic ic,
XIMResourceList res,
CARD16 *data,
- INT16 data_len,
+ CARD16 data_len,
XPointer value,
BITMASK32 mode)
{
@@ -250,18 +252,24 @@ _XimAttributeToValue(
case XimType_XIMStyles:
{
- INT16 num = data[0];
+ CARD16 num = data[0];
register CARD32 *style_list = (CARD32 *)&data[2];
XIMStyle *style;
XIMStyles *rep;
register int i;
char *p;
- int alloc_len;
+ unsigned int alloc_len;
if (!(value))
return False;
+ if (num > (USHRT_MAX / sizeof(XIMStyle)))
+ return False;
+ if ((2 * sizeof(CARD16) + (num * sizeof(CARD32))) > data_len)
+ return False;
alloc_len = sizeof(XIMStyles) + sizeof(XIMStyle) * num;
+ if (alloc_len < sizeof(XIMStyles))
+ return False;
if (!(p = Xmalloc(alloc_len)))
return False;
@@ -313,7 +321,7 @@ _XimAttributeToValue(
case XimType_XFontSet:
{
- INT16 len = data[0];
+ CARD16 len = data[0];
char *base_name;
XFontSet rep = (XFontSet)NULL;
char **missing_list = NULL;
@@ -324,11 +332,12 @@ _XimAttributeToValue(
return False;
if (!ic)
return False;
-
+ if (len > data_len)
+ return False;
if (!(base_name = Xmalloc(len + 1)))
return False;
- (void)strncpy(base_name, (char *)&data[1], (int)len);
+ (void)strncpy(base_name, (char *)&data[1], (size_t)len);
base_name[len] = '\0';
if (mode & XIM_PREEDIT_ATTR) {
@@ -357,19 +366,25 @@ _XimAttributeToValue(
case XimType_XIMHotKeyTriggers:
{
- INT32 num = *((CARD32 *)data);
+ CARD32 num = *((CARD32 *)data);
register CARD32 *key_list = (CARD32 *)&data[2];
XIMHotKeyTrigger *key;
XIMHotKeyTriggers *rep;
register int i;
char *p;
- int alloc_len;
+ unsigned int alloc_len;
if (!(value))
return False;
+ if (num > (UINT_MAX / sizeof(XIMHotKeyTrigger)))
+ return False;
+ if ((2 * sizeof(CARD16) + (num * 3 * sizeof(CARD32))) > data_len)
+ return False;
alloc_len = sizeof(XIMHotKeyTriggers)
+ sizeof(XIMHotKeyTrigger) * num;
+ if (alloc_len < sizeof(XIMHotKeyTriggers))
+ return False;
if (!(p = Xmalloc(alloc_len)))
return False;
@@ -1378,13 +1393,13 @@ _XimEncodeSavedICATTRIBUTE(
static unsigned int
_XimCountNumberOfAttr(
- INT16 total,
- CARD16 *attr,
- int *names_len)
+ CARD16 total,
+ CARD16 *attr,
+ unsigned int *names_len)
{
unsigned int n;
- INT16 len;
- INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */
+ CARD16 len;
+ CARD16 min_len = sizeof(CARD16) /* sizeof attribute ID */
+ sizeof(CARD16) /* sizeof type of value */
+ sizeof(INT16); /* sizeof length of attribute */
@@ -1392,6 +1407,9 @@ _XimCountNumberOfAttr(
*names_len = 0;
while (total > min_len) {
len = attr[2];
+ if (len > (total - min_len)) {
+ return 0;
+ }
*names_len += (len + 1);
len += (min_len + XIM_PAD(len + 2));
total -= len;
@@ -1406,17 +1424,15 @@ _XimGetAttributeID(
Xim im,
CARD16 *buf)
{
- unsigned int n;
+ unsigned int n, names_len, values_len;
XIMResourceList res;
char *names;
- int names_len;
XPointer tmp;
XIMValuesList *values_list;
char **values;
- int values_len;
register int i;
- INT16 len;
- INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */
+ CARD16 len;
+ CARD16 min_len = sizeof(CARD16) /* sizeof attribute ID */
+ sizeof(CARD16) /* sizeof type of value */
+ sizeof(INT16); /* sizeof length of attr */
/*
diff --git a/nx-X11/lib/modules/im/ximcp/imThaiFlt.c b/nx-X11/lib/modules/im/ximcp/imThaiFlt.c
index 401bd9a08..1314588b4 100644
--- a/nx-X11/lib/modules/im/ximcp/imThaiFlt.c
+++ b/nx-X11/lib/modules/im/ximcp/imThaiFlt.c
@@ -129,7 +129,7 @@ char const tactis_chtype[TACTIS_CHARS] = {
static
char const write_rules_lookup[CH_CLASSES][CH_CLASSES] = {
- /* Table 0: writing/outputing rules */
+ /* Table 0: writing/outputting rules */
/* row: leading char, column: following char */
/* CTRL NON CONS LV FV1 FV2 FV3 BV1 BV2 BD TONE AD1 AD2 AD3 AV1 AV2 AV3 */
{XC, NC, NC, NC, NC, NC, NC, NC, NC, NC, NC, NC, NC, NC, NC, NC, NC}/*CTRL*/
@@ -821,7 +821,7 @@ XThaiTranslateKey(
* 4 of the keymap.
* Since we don't know whether ThaiCat keyboard or WTT keyboard is
* in use, the same mapping is done for all Thai input.
- * We just arbitary choose to use column 3 keysyms as the indices of
+ * We just arbitrarily choose to use column 3 keysyms as the indices of
* this mapping.
* When the control key is also hold, this mapping has no effect.
*/
diff --git a/nx-X11/lib/modules/im/ximcp/imTrX.c b/nx-X11/lib/modules/im/ximcp/imTrX.c
index 148b7fc90..be7118c6f 100644
--- a/nx-X11/lib/modules/im/ximcp/imTrX.c
+++ b/nx-X11/lib/modules/im/ximcp/imTrX.c
@@ -93,6 +93,7 @@ _XimXFreeIntrCallback(
Xfree(rec);
rec = next;
}
+ spec->intr_cb = NULL;
return;
}
diff --git a/nx-X11/lib/modules/im/ximcp/imTrans.c b/nx-X11/lib/modules/im/ximcp/imTrans.c
index 7f936cff6..212a1238f 100644
--- a/nx-X11/lib/modules/im/ximcp/imTrans.c
+++ b/nx-X11/lib/modules/im/ximcp/imTrans.c
@@ -176,6 +176,7 @@ _XimFreeTransIntrCallback(
Xfree(rec);
rec = next;
}
+ spec->intr_cb = NULL;
return;
}
diff --git a/nx-X11/lib/modules/lc/gen/lcGenConv.c b/nx-X11/lib/modules/lc/gen/lcGenConv.c
index 799f49a30..b05fde6d2 100644
--- a/nx-X11/lib/modules/lc/gen/lcGenConv.c
+++ b/nx-X11/lib/modules/lc/gen/lcGenConv.c
@@ -940,7 +940,7 @@ wcstombs_org(
if (*to_left < defstr_len)
break;
if (outbufptr) {
- strncpy((char *)outbufptr, default_string, defstr_len);
+ memcpy(outbufptr, default_string, defstr_len);
outbufptr += defstr_len;
}
(*to_left) -= defstr_len;
@@ -976,7 +976,7 @@ wcstombs_org(
if (*to_left < length)
break;
if (outbufptr) {
- strncpy((char *)outbufptr, encoding, length);
+ memcpy(outbufptr, encoding, length);
outbufptr += length;
}
(*to_left) -= length;
@@ -1966,7 +1966,7 @@ wcstostr(
if (*to_left < defstr_len)
break;
if (outbufptr) {
- strncpy((char *)outbufptr, default_string, defstr_len);
+ memcpy(outbufptr, default_string, defstr_len);
outbufptr += defstr_len;
}
(*to_left) -= defstr_len;
@@ -2005,7 +2005,7 @@ wcstostr(
break;
if (outbufptr) {
- strncpy((char *)outbufptr, encoding, length);
+ memcpy(outbufptr, encoding, length);
outbufptr += length;
}
(*to_left) -= length;
@@ -2462,7 +2462,7 @@ strtombs(
if (*to_left < length)
break;
if (outbufptr) {
- strncpy((char *)outbufptr, encoding, length);
+ memcpy(outbufptr, encoding, length);
outbufptr += length;
}
(*to_left) -= length;
diff --git a/nx-X11/lib/modules/om/generic/omGeneric.c b/nx-X11/lib/modules/om/generic/omGeneric.c
index ec612d379..39c4f1bf4 100644
--- a/nx-X11/lib/modules/om/generic/omGeneric.c
+++ b/nx-X11/lib/modules/om/generic/omGeneric.c
@@ -702,7 +702,7 @@ parse_omit_name(
switch (num_fields) {
case 12:
- /* This is the best way to have specifed the fontset. In this
+ /* This is the best way to have specified the fontset. In this
* case, there is no original encoding. E.g.,
* -*-*-*-*-*-*-14-*-*-*-*-*
* To this, we'll append a dash:
@@ -771,7 +771,7 @@ parse_omit_name(
if ((font_data->xlfd_name = get_font_name(oc, buf)) != NULL)
return True;
- /* This may mot be needed anymore as XListFonts() takes care of this */
+ /* This may not be needed anymore as XListFonts() takes care of this */
if (num_fields < 12) {
if ((last - buf) > (XLFD_MAX_LEN - 2))
return -1;
@@ -1113,7 +1113,7 @@ parse_fontname(
goto err;
} else if(ret == True) {
/*
- * We can't just loop thru fontset->font_data to
+ * We can't just loop through fontset->font_data to
* find the first (ie. best) match: parse_fontdata
* will try a substitute font if no primary one could
* be matched. It returns the required information in
@@ -1640,7 +1640,7 @@ close_om(
for (count = gen->data_num; count-- > 0; data++) {
Xfree(data->charset_list);
data->charset_list = NULL;
-
+
/* free font_data for om */
free_fontdataOM(data->font_data,data->font_data_count);
Xfree(data->font_data);
@@ -1908,7 +1908,8 @@ init_om(
char **required_list;
XOrientation *orientation;
char **value, buf[BUFSIZ], *bufptr;
- int count = 0, num = 0, length = 0;
+ int count = 0, num = 0;
+ unsigned int length = 0;
_XlcGetResource(lcd, "XLC_FONTSET", "on_demand_loading", &value, &count);
if (count > 0 && _XlcCompareISOLatin1(*value, "True") == 0)
@@ -2048,7 +2049,7 @@ init_om(
/* directional dependent drawing */
om->core.directional_dependent = False;
- /* contexual drawing */
+ /* contextual drawing */
om->core.contextual_drawing = False;
/* context dependent */
diff --git a/nx-X11/lib/modules/om/generic/omTextEsc.c b/nx-X11/lib/modules/om/generic/omTextEsc.c
index df1fb10c0..2aaff73db 100644
--- a/nx-X11/lib/modules/om/generic/omTextEsc.c
+++ b/nx-X11/lib/modules/om/generic/omTextEsc.c
@@ -169,10 +169,10 @@ TextWidthWithFontSet(
*
*/
- if(fd == (FontData) NULL ||
- (font = font_set->font) == (XFontStruct *) NULL) {
+ if((font = font_set->font) == (XFontStruct *) NULL) {
- if((font = fd->font) == (XFontStruct *) NULL)
+ if(fd == (FontData) NULL ||
+ (font = fd->font) == (XFontStruct *) NULL)
break;
}
diff --git a/nx-X11/lib/src/Context.c b/nx-X11/lib/src/Context.c
index 8a078713a..a2f9e1255 100644
--- a/nx-X11/lib/src/Context.c
+++ b/nx-X11/lib/src/Context.c
@@ -146,13 +146,14 @@ static void _XFreeContextDB(Display *display)
Xfree(db->table);
_XFreeMutex(&db->linfo);
Xfree(db);
+ display->context_db = NULL;
}
}
/* Public routines. */
/* Save the given value of data to correspond with the keys XID and context.
- Returns nonzero error code if an error has occured, 0 otherwise.
+ Returns nonzero error code if an error has occurred, 0 otherwise.
Possible errors are Out-of-memory.
*/
@@ -230,7 +231,7 @@ int XSaveContext(
/* Given an XID and context, returns the associated data. Note that data
here is a pointer since it is a return value. Returns nonzero error code
- if an error has occured, 0 otherwise. Possible errors are Entry-not-found.
+ if an error has occurred, 0 otherwise. Possible errors are Entry-not-found.
*/
int XFindContext(Display *display, XID rid, XContext context, XPointer *data)
diff --git a/nx-X11/lib/src/CopyCmap.c b/nx-X11/lib/src/CopyCmap.c
index 5444550cd..b37aba733 100644
--- a/nx-X11/lib/src/CopyCmap.c
+++ b/nx-X11/lib/src/CopyCmap.c
@@ -53,12 +53,17 @@ Colormap XCopyColormapAndFree(
mid = req->mid = XAllocID(dpy);
req->srcCmap = src_cmap;
+ /* re-lock the display to keep XID handling in sync */
UnlockDisplay(dpy);
SyncHandle();
+ LockDisplay(dpy);
#if XCMS
_XcmsCopyCmapRecAndFree(dpy, src_cmap, mid);
#endif
+ UnlockDisplay(dpy);
+ SyncHandle();
+
return(mid);
}
diff --git a/nx-X11/lib/src/CrCmap.c b/nx-X11/lib/src/CrCmap.c
index 9904c7dda..1b18a15bb 100644
--- a/nx-X11/lib/src/CrCmap.c
+++ b/nx-X11/lib/src/CrCmap.c
@@ -48,12 +48,12 @@ Colormap XCreateColormap(
if (visual == CopyFromParent) req->visual = CopyFromParent;
else req->visual = visual->visualid;
- UnlockDisplay(dpy);
- SyncHandle();
-
#ifdef XCMS
_XcmsAddCmapRec(dpy, mid, w, visual);
#endif
+ UnlockDisplay(dpy);
+ SyncHandle();
+
return(mid);
}
diff --git a/nx-X11/lib/src/Depths.c b/nx-X11/lib/src/Depths.c
index a8b719d00..dace21e52 100644
--- a/nx-X11/lib/src/Depths.c
+++ b/nx-X11/lib/src/Depths.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <stdio.h>
/*
@@ -49,7 +50,7 @@ int *XListDepths (
register Depth *dp;
register int i;
- depths = Xmalloc (count * sizeof(int));
+ depths = Xmallocarray (count, sizeof(int));
if (!depths) return NULL;
for (i = 0, dp = scr->depths; i < count; i++, dp++)
depths[i] = dp->depth;
diff --git a/nx-X11/lib/src/ErrDes.c b/nx-X11/lib/src/ErrDes.c
index f13e3dce4..ff7e9be84 100644
--- a/nx-X11/lib/src/ErrDes.c
+++ b/nx-X11/lib/src/ErrDes.c
@@ -204,9 +204,9 @@ XGetErrorDatabaseText(
result.addr = (XPointer)NULL;
if (!result.addr) {
result.addr = (XPointer) defaultp;
- result.size = strlen(defaultp) + 1;
+ result.size = (unsigned)strlen(defaultp) + 1;
}
- (void) strncpy (buffer, (char *) result.addr, nbytes);
+ (void) strncpy (buffer, (char *) result.addr, (size_t)nbytes);
if (result.size > nbytes) buffer[nbytes-1] = '\0';
return 0;
}
diff --git a/nx-X11/lib/src/ErrHndlr.c b/nx-X11/lib/src/ErrHndlr.c
index 167a68b1e..0664ea936 100644
--- a/nx-X11/lib/src/ErrHndlr.c
+++ b/nx-X11/lib/src/ErrHndlr.c
@@ -84,3 +84,28 @@ XSetIOErrorHandler(XIOErrorHandler handler)
return (XIOErrorHandler) oldhandler;
}
+
+/*
+ * XSetIOErrorExitHandler - This procedure sets the X fatal I/O error
+ * exit function to be the specified routine. If NULL is passed in
+ * the original error exit function is restored. The default routine
+ * calls exit(3).
+ */
+void
+XSetIOErrorExitHandler(
+ Display *dpy,
+ XIOErrorExitHandler handler,
+ void *user_data)
+{
+ LockDisplay(dpy);
+
+ if (handler != NULL) {
+ dpy->exit_handler = handler;
+ dpy->exit_handler_data = user_data;
+ }
+ else {
+ dpy->exit_handler = _XDefaultIOErrorExit;
+ dpy->exit_handler_data = NULL;
+ }
+ UnlockDisplay(dpy);
+}
diff --git a/nx-X11/lib/src/FSWrap.c b/nx-X11/lib/src/FSWrap.c
index 1b244f43c..035dbcd3e 100644
--- a/nx-X11/lib/src/FSWrap.c
+++ b/nx-X11/lib/src/FSWrap.c
@@ -63,6 +63,7 @@ from The Open Group.
#include "Xlcint.h"
#include <ctype.h>
#include <nx-X11/Xos.h>
+#include "reallocarray.h"
#define XMAXLIST 256
@@ -112,11 +113,11 @@ _XParseBaseFontNameList(
if (!*ptr)
break;
}
- if (!(list = Xmalloc(sizeof(char *) * (*num + 1)))) {
+ if (!(list = Xmallocarray((*num + 1), sizeof(char *)))) {
Xfree(psave);
return (char **)NULL;
}
- memcpy((char *)list, (char *)plist, sizeof(char *) * (*num));
+ memcpy((char *)list, (char *)plist, sizeof(char *) * (size_t) (*num));
*(list + *num) = NULL;
return list;
@@ -133,14 +134,14 @@ copy_string_list(
if (string_list == NULL || list_count <= 0)
return (char **) NULL;
- string_list_ret = Xmalloc(sizeof(char *) * list_count);
+ string_list_ret = Xmallocarray(list_count, sizeof(char *));
if (string_list_ret == NULL)
return (char **) NULL;
list_src = string_list;
count = list_count;
for (length = 0; count-- > 0; list_src++)
- length += strlen(*list_src) + 1;
+ length = length + (int) strlen(*list_src) + 1;
dst = Xmalloc(length);
if (dst == NULL) {
diff --git a/nx-X11/lib/src/FetchName.c b/nx-X11/lib/src/FetchName.c
index 52c65c52c..70facfb5a 100644
--- a/nx-X11/lib/src/FetchName.c
+++ b/nx-X11/lib/src/FetchName.c
@@ -51,7 +51,7 @@ Status XFetchName (
}
if ( (actual_type == XA_STRING) && (actual_format == 8) ) {
- /* The data returned by XGetWindowProperty is guarranteed to
+ /* The data returned by XGetWindowProperty is guaranteed to
contain one extra byte that is null terminated to make retrieveing
string properties easy. */
@@ -82,7 +82,7 @@ Status XGetIconName (
}
if ( (actual_type == XA_STRING) && (actual_format == 8) ) {
- /* The data returned by XGetWindowProperty is guarranteed to
+ /* The data returned by XGetWindowProperty is guaranteed to
contain one extra byte that is null terminated to make retrieveing
string properties easy. */
diff --git a/nx-X11/lib/src/Font.c b/nx-X11/lib/src/Font.c
index 6bbab3f19..cf564d894 100644
--- a/nx-X11/lib/src/Font.c
+++ b/nx-X11/lib/src/Font.c
@@ -31,6 +31,7 @@ authorization from the X Consortium and the XFree86 Project.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
#if defined(XF86BIGFONT)
@@ -101,12 +102,14 @@ XFontStruct *XLoadQueryFont(
XF86BigfontCodes *extcodes = _XF86BigfontCodes(dpy);
#endif
+ if (name != NULL && strlen(name) >= USHRT_MAX)
+ return NULL;
if (_XF86LoadQueryLocaleFont(dpy, name, &font_result, (Font *)0))
return font_result;
LockDisplay(dpy);
GetReq(OpenFont, req);
- seq = dpy->request;
- nbytes = req->nbytes = name ? strlen(name) : 0;
+ seq = dpy->request; /* Can't use extended sequence number here */
+ nbytes = req->nbytes = (CARD16) (name ? strlen(name) : 0);
req->fid = fid = XAllocID(dpy);
req->length += (nbytes+3)>>2;
Data (dpy, name, nbytes);
@@ -245,8 +248,8 @@ _XQueryFont (
/* nFontProps is a CARD16 */
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if ((nbytes >> 2) <= reply_left) {
- size_t pbytes = reply.nFontProps * sizeof(XFontProp);
- fs->properties = Xmalloc (pbytes);
+ fs->properties = Xmallocarray (reply.nFontProps,
+ sizeof(XFontProp));
}
if (! fs->properties) {
Xfree(fs);
@@ -266,8 +269,8 @@ _XQueryFont (
if (reply.nCharInfos < (INT_MAX / sizeof(XCharStruct))) {
nbytes = reply.nCharInfos * SIZEOF(xCharInfo);
if ((nbytes >> 2) <= reply_left) {
- size_t cibytes = reply.nCharInfos * sizeof(XCharStruct);
- fs->per_char = Xmalloc (cibytes);
+ fs->per_char = Xmallocarray (reply.nCharInfos,
+ sizeof(XCharStruct));
}
}
if (! fs->per_char) {
@@ -489,8 +492,8 @@ _XF86BigfontQueryFont (
/* nFontProps is a CARD16 */
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if ((nbytes >> 2) <= reply_left) {
- size_t pbytes = reply.nFontProps * sizeof(XFontProp);
- fs->properties = Xmalloc (pbytes);
+ fs->properties = Xmallocarray (reply.nFontProps,
+ sizeof(XFontProp));
}
if (! fs->properties) {
Xfree(fs);
@@ -529,7 +532,8 @@ _XF86BigfontQueryFont (
_XEatDataWords(dpy, reply_left);
return (XFontStruct *)NULL;
}
- if (! (fs->per_char = Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) {
+ if (! (fs->per_char = Xmallocarray (reply.nCharInfos,
+ sizeof(XCharStruct)))) {
Xfree(pUniqCI);
Xfree(fs->properties);
Xfree(fs);
@@ -652,7 +656,7 @@ int _XF86LoadQueryLocaleFont(
XFontStruct **xfp,
Font *fidp)
{
- int l;
+ size_t l;
const char *charset, *p;
char buf[256];
XFontStruct *fs;
@@ -661,7 +665,7 @@ int _XF86LoadQueryLocaleFont(
if (!name)
return 0;
l = strlen(name);
- if (l < 2 || name[l - 1] != '*' || name[l - 2] != '-')
+ if (l < 2 || name[l - 1] != '*' || name[l - 2] != '-' || l >= USHRT_MAX)
return 0;
charset = NULL;
/* next three lines stolen from _XkbGetCharset() */
@@ -673,7 +677,7 @@ int _XF86LoadQueryLocaleFont(
charset = "ISO8859-1";
p = charset + 7;
}
- if (l - 2 - (p - charset) < 0)
+ if (l - 2 < p - charset)
return 0;
if (_XlcNCompareISOLatin1(name + l - 2 - (p - charset), charset, p - charset))
return 0;
diff --git a/nx-X11/lib/src/FontInfo.c b/nx-X11/lib/src/FontInfo.c
index a2d12c2ec..0e4ae097b 100644
--- a/nx-X11/lib/src/FontInfo.c
+++ b/nx-X11/lib/src/FontInfo.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
#if defined(XF86BIGFONT)
@@ -57,10 +58,13 @@ XFontStruct **info) /* RETURN */
register xListFontsReq *req;
int j;
+ if (pattern != NULL && strlen(pattern) >= USHRT_MAX)
+ return NULL;
+
LockDisplay(dpy);
GetReq(ListFontsWithInfo, req);
req->maxNames = maxNames;
- nbytes = req->nbytes = pattern ? strlen (pattern) : 0;
+ nbytes = req->nbytes = pattern ? (CARD16) strlen (pattern) : 0;
req->length += (nbytes + 3) >> 2;
_XSend (dpy, pattern, nbytes);
/* use _XSend instead of Data, since subsequent _XReply will flush buffer */
@@ -91,22 +95,22 @@ XFontStruct **info) /* RETURN */
XFontStruct * tmp_finfo;
char ** tmp_flist;
- tmp_finfo = Xrealloc (finfo, sizeof(XFontStruct) * size);
+ tmp_finfo = Xreallocarray (finfo, size, sizeof(XFontStruct));
if (tmp_finfo)
finfo = tmp_finfo;
else
goto badmem;
- tmp_flist = Xrealloc (flist, sizeof(char *) * (size+1));
+ tmp_flist = Xreallocarray (flist, size + 1, sizeof(char *));
if (tmp_flist)
flist = tmp_flist;
else
goto badmem;
}
else {
- if (! (finfo = Xmalloc(sizeof(XFontStruct) * size)))
+ if (! (finfo = Xmallocarray(size, sizeof(XFontStruct))))
goto clearwire;
- if (! (flist = Xmalloc(sizeof(char *) * (size+1)))) {
+ if (! (flist = Xmallocarray(size + 1, sizeof(char *)))) {
Xfree(finfo);
goto clearwire;
}
@@ -137,8 +141,8 @@ XFontStruct **info) /* RETURN */
/* nFontProps is a CARD16 */
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if ((nbytes >> 2) <= reply_left) {
- size_t pbytes = reply.nFontProps * sizeof(XFontProp);
- fs->properties = Xmalloc (pbytes);
+ fs->properties = Xmallocarray (reply.nFontProps,
+ sizeof(XFontProp));
}
if (! fs->properties)
goto badmem;
diff --git a/nx-X11/lib/src/FontNames.c b/nx-X11/lib/src/FontNames.c
index ec7d90fa2..31c2e0641 100644
--- a/nx-X11/lib/src/FontNames.c
+++ b/nx-X11/lib/src/FontNames.c
@@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
char **
@@ -50,10 +51,13 @@ int *actualCount) /* RETURN */
register xListFontsReq *req;
unsigned long rlen = 0;
+ if (pattern != NULL && strlen(pattern) >= USHRT_MAX)
+ return NULL;
+
LockDisplay(dpy);
GetReq(ListFonts, req);
req->maxNames = maxNames;
- nbytes = req->nbytes = pattern ? strlen (pattern) : 0;
+ nbytes = req->nbytes = pattern ? (CARD16) strlen (pattern) : 0;
req->length += (nbytes + 3) >> 2;
_XSend (dpy, pattern, nbytes);
/* use _XSend instead of Data, since following _XReply will flush buffer */
@@ -66,7 +70,7 @@ int *actualCount) /* RETURN */
}
if (rep.nFonts) {
- flist = Xmalloc (rep.nFonts * sizeof(char *));
+ flist = Xmallocarray (rep.nFonts, sizeof(char *));
if (rep.length > 0 && rep.length < (INT_MAX >> 2)) {
rlen = rep.length << 2;
ch = Xmalloc(rlen + 1);
diff --git a/nx-X11/lib/src/FreeCmap.c b/nx-X11/lib/src/FreeCmap.c
index e2b76fa6f..68496dd88 100644
--- a/nx-X11/lib/src/FreeCmap.c
+++ b/nx-X11/lib/src/FreeCmap.c
@@ -41,12 +41,12 @@ XFreeColormap(
LockDisplay(dpy);
GetResReq(FreeColormap, cmap, req);
- UnlockDisplay(dpy);
- SyncHandle();
-
#ifdef XCMS
_XcmsDeleteCmapRec(dpy, cmap);
#endif
+ UnlockDisplay(dpy);
+ SyncHandle();
+
return 1;
}
diff --git a/nx-X11/lib/src/GetAtomNm.c b/nx-X11/lib/src/GetAtomNm.c
index 32de50d23..41ec3bac6 100644
--- a/nx-X11/lib/src/GetAtomNm.c
+++ b/nx-X11/lib/src/GetAtomNm.c
@@ -36,7 +36,6 @@ char *_XGetAtomName(
Atom atom)
{
xResourceReq *req;
- char *name;
register Entry *table;
register int idx;
register Entry e;
@@ -45,10 +44,7 @@ char *_XGetAtomName(
table = dpy->atoms->table;
for (idx = TABLESIZE; --idx >= 0; ) {
if ((e = *table++) && (e->atom == atom)) {
- idx = strlen(EntryName(e)) + 1;
- if ((name = Xmalloc(idx)))
- strcpy(name, EntryName(e));
- return name;
+ return strdup(EntryName(e));
}
}
}
@@ -87,8 +83,8 @@ char *XGetAtomName(
}
typedef struct {
- unsigned long start_seq;
- unsigned long stop_seq;
+ uint64_t start_seq;
+ uint64_t stop_seq;
Atom *atoms;
char **names;
int idx;
@@ -107,10 +103,11 @@ Bool _XGetAtomNameHandler(
register _XGetAtomNameState *state;
xGetAtomNameReply replbuf;
register xGetAtomNameReply *repl;
+ uint64_t last_request_read = X_DPY_GET_LAST_REQUEST_READ(dpy);
state = (_XGetAtomNameState *)data;
- if (dpy->last_request_read < state->start_seq ||
- dpy->last_request_read > state->stop_seq)
+ if (last_request_read < state->start_seq ||
+ last_request_read > state->stop_seq)
return False;
while (state->idx < state->count && state->names[state->idx])
state->idx++;
@@ -152,7 +149,7 @@ XGetAtomNames (
int missed = -1;
LockDisplay(dpy);
- async_state.start_seq = dpy->request + 1;
+ async_state.start_seq = X_DPY_GET_REQUEST(dpy) + 1;
async_state.atoms = atoms;
async_state.names = names_return;
async_state.idx = 0;
@@ -165,7 +162,7 @@ XGetAtomNames (
for (i = 0; i < count; i++) {
if (!(names_return[i] = _XGetAtomName(dpy, atoms[i]))) {
missed = i;
- async_state.stop_seq = dpy->request;
+ async_state.stop_seq = X_DPY_GET_REQUEST(dpy);
}
}
if (missed >= 0) {
diff --git a/nx-X11/lib/src/GetColor.c b/nx-X11/lib/src/GetColor.c
index cd0eb9f63..f38dea9c5 100644
--- a/nx-X11/lib/src/GetColor.c
+++ b/nx-X11/lib/src/GetColor.c
@@ -27,6 +27,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include "Xlibint.h"
#include "Xcmsint.h"
@@ -48,6 +49,9 @@ XColor *exact_def) /* RETURN */
XcmsColor cmsColor_exact;
Status ret;
+ if (colorname != NULL && strlen(colorname) >= USHRT_MAX)
+ return (0);
+
#ifdef XCMS
/*
* Let's Attempt to use Xcms and i18n approach to Parse Color
@@ -83,7 +87,7 @@ XColor *exact_def) /* RETURN */
GetReq(AllocNamedColor, req);
req->cmap = cmap;
- nbytes = req->nbytes = strlen(colorname);
+ nbytes = req->nbytes = (CARD16) strlen(colorname);
req->length += (nbytes + 3) >> 2; /* round up to mult of 4 */
_XSend(dpy, colorname, nbytes);
diff --git a/nx-X11/lib/src/GetDflt.c b/nx-X11/lib/src/GetDflt.c
index c2cc1da47..0f6b5f6fd 100644
--- a/nx-X11/lib/src/GetDflt.c
+++ b/nx-X11/lib/src/GetDflt.c
@@ -141,7 +141,7 @@ InitDefaults(
if (dpy->xdefaults == NULL) {
const char *slashDotXdefaults = "/.Xdefaults";
- (void) GetHomeDir (fname, PATH_MAX - strlen (slashDotXdefaults) - 1);
+ (void) GetHomeDir (fname, (int) (PATH_MAX - strlen (slashDotXdefaults) - 1));
(void) strcat (fname, slashDotXdefaults);
xdb = XrmGetFileDatabase (fname);
} else {
@@ -152,9 +152,9 @@ InitDefaults(
const char *slashDotXdefaultsDash = "/.Xdefaults-";
int len;
- (void) GetHomeDir (fname, PATH_MAX - strlen (slashDotXdefaultsDash) - 1);
+ (void) GetHomeDir (fname, (int) (PATH_MAX - strlen (slashDotXdefaultsDash) - 1));
(void) strcat (fname, slashDotXdefaultsDash);
- len = strlen (fname);
+ len = (int) strlen (fname);
(void) _XGetHostname (fname+len, PATH_MAX-len);
xenv = fname;
}
diff --git a/nx-X11/lib/src/GetFPath.c b/nx-X11/lib/src/GetFPath.c
index 87d257615..7d5153b6d 100644
--- a/nx-X11/lib/src/GetFPath.c
+++ b/nx-X11/lib/src/GetFPath.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
char **XGetFontPath(
@@ -49,7 +50,7 @@ char **XGetFontPath(
(void) _XReply (dpy, (xReply *) &rep, 0, xFalse);
if (rep.nPaths) {
- flist = Xmalloc(rep.nPaths * sizeof (char *));
+ flist = Xmallocarray(rep.nPaths, sizeof (char *));
if (rep.length < (INT_MAX >> 2)) {
nbytes = (unsigned long) rep.length << 2;
ch = Xmalloc (nbytes + 1);
diff --git a/nx-X11/lib/src/GetHints.c b/nx-X11/lib/src/GetHints.c
index 7bfd35358..dafe5174a 100644
--- a/nx-X11/lib/src/GetHints.c
+++ b/nx-X11/lib/src/GetHints.c
@@ -315,14 +315,14 @@ XGetClassHint(
return (0);
if ( (actual_type == XA_STRING) && (actual_format == 8) ) {
- len_name = strlen((char *) data);
+ len_name = (int) strlen((char *) data);
if (! (classhint->res_name = Xmalloc(len_name + 1))) {
Xfree(data);
return (0);
}
strcpy(classhint->res_name, (char *) data);
if (len_name == nitems) len_name--;
- len_class = strlen((char *) (data+len_name+1));
+ len_class = (int) strlen((char *) (data+len_name+1));
if (! (classhint->res_class = Xmalloc(len_class + 1))) {
Xfree(classhint->res_name);
classhint->res_name = (char *) NULL;
diff --git a/nx-X11/lib/src/GetImage.c b/nx-X11/lib/src/GetImage.c
index 96d9ce337..c6e6e633a 100644
--- a/nx-X11/lib/src/GetImage.c
+++ b/nx-X11/lib/src/GetImage.c
@@ -34,15 +34,24 @@ in this Software without prior written authorization from The Open Group.
#define ROUNDUP(nbytes, pad) (((((nbytes) - 1) + (pad)) / (pad)) * (pad))
-static unsigned int Ones( /* HACKMEM 169 */
- unsigned long mask)
+#ifdef HAVE___BUILTIN_POPCOUNTL
+# define Ones __builtin_popcountl
+#else
+/*
+ * Count the number of bits set to 1 in a 32-bit word.
+ * Algorithm from MIT AI Lab Memo 239: "HAKMEM", ITEM 169.
+ * http://dspace.mit.edu/handle/1721.1/6086
+ */
+static inline unsigned int
+Ones(unsigned long mask)
{
register unsigned long y;
- y = (mask >> 1) &033333333333;
+ y = (mask >> 1) & 033333333333;
y = mask - y - ((y >>1) & 033333333333);
return ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077));
}
+#endif
XImage *XGetImage (
register Display *dpy,
diff --git a/nx-X11/lib/src/GetMoEv.c b/nx-X11/lib/src/GetMoEv.c
index ad9c77277..d723f3788 100644
--- a/nx-X11/lib/src/GetMoEv.c
+++ b/nx-X11/lib/src/GetMoEv.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
XTimeCoord *XGetMotionEvents(
@@ -53,7 +54,7 @@ XTimeCoord *XGetMotionEvents(
}
if (rep.nEvents && (rep.nEvents < (INT_MAX / sizeof(XTimeCoord))))
- tc = Xmalloc(rep.nEvents * sizeof(XTimeCoord));
+ tc = Xmallocarray(rep.nEvents, sizeof(XTimeCoord));
if (tc == NULL) {
/* server returned either no events or a bad event count */
*nEvents = 0;
diff --git a/nx-X11/lib/src/GetPntMap.c b/nx-X11/lib/src/GetPntMap.c
index 07625f8a0..4219a1101 100644
--- a/nx-X11/lib/src/GetPntMap.c
+++ b/nx-X11/lib/src/GetPntMap.c
@@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
#ifdef MIN /* some systems define this in <sys/param.h> */
@@ -112,8 +113,7 @@ XGetKeyboardMapping (Display *dpy,
nkeysyms = rep.length;
if (nkeysyms > 0) {
if (nkeysyms < (INT_MAX / sizeof (KeySym))) {
- nbytes = nkeysyms * sizeof (KeySym);
- mapping = Xmalloc (nbytes);
+ mapping = Xmallocarray (nkeysyms, sizeof (KeySym));
}
if (! mapping) {
_XEatDataWords(dpy, rep.length);
diff --git a/nx-X11/lib/src/GetRGBCMap.c b/nx-X11/lib/src/GetRGBCMap.c
index 746b53fbf..1e04f1612 100644
--- a/nx-X11/lib/src/GetRGBCMap.c
+++ b/nx-X11/lib/src/GetRGBCMap.c
@@ -33,6 +33,7 @@ from The Open Group.
#include <nx-X11/Xlibint.h>
#include <nx-X11/Xutil.h>
#include "Xatomtype.h"
+#include "reallocarray.h"
#include <nx-X11/Xatom.h>
Status XGetRGBColormaps (
@@ -99,7 +100,7 @@ Status XGetRGBColormaps (
/*
* allocate array
*/
- cmaps = Xmalloc (ncmaps * sizeof (XStandardColormap));
+ cmaps = Xmallocarray (ncmaps, sizeof (XStandardColormap));
if (!cmaps) {
Xfree (data);
return False;
diff --git a/nx-X11/lib/src/GetStCmap.c b/nx-X11/lib/src/GetStCmap.c
index 560de67ba..865d9c455 100644
--- a/nx-X11/lib/src/GetStCmap.c
+++ b/nx-X11/lib/src/GetStCmap.c
@@ -1,4 +1,3 @@
-
/***********************************************************
Copyright 1987, 1998 The Open Group
@@ -111,7 +110,7 @@ Status XGetStandardColormap (
cmap->blue_mult = use->blue_mult;
cmap->base_pixel = use->base_pixel;
- Xfree (stdcmaps); /* don't need alloced memory */
+ Xfree (stdcmaps); /* don't need allocated memory */
}
return stat;
}
diff --git a/nx-X11/lib/src/GetWAttrs.c b/nx-X11/lib/src/GetWAttrs.c
index c10824cf4..0775eabc8 100644
--- a/nx-X11/lib/src/GetWAttrs.c
+++ b/nx-X11/lib/src/GetWAttrs.c
@@ -30,8 +30,8 @@ in this Software without prior written authorization from The Open Group.
#include "Xlibint.h"
typedef struct _WAttrsState {
- unsigned long attr_seq;
- unsigned long geom_seq;
+ uint64_t attr_seq;
+ uint64_t geom_seq;
XWindowAttributes *attr;
} _XWAttrsState;
@@ -47,10 +47,11 @@ _XWAttrsHandler(
xGetWindowAttributesReply replbuf;
register xGetWindowAttributesReply *repl;
register XWindowAttributes *attr;
+ uint64_t last_request_read = X_DPY_GET_LAST_REQUEST_READ(dpy);
state = (_XWAttrsState *)data;
- if (dpy->last_request_read != state->attr_seq) {
- if (dpy->last_request_read == state->geom_seq &&
+ if (last_request_read != state->attr_seq) {
+ if (last_request_read == state->geom_seq &&
!state->attr &&
rep->generic.type == X_Error &&
rep->error.errorCode == BadDrawable)
@@ -86,7 +87,7 @@ _XWAttrsHandler(
Status
_XGetWindowAttributes(
- register Display *dpy,
+ Display *dpy,
Window w,
XWindowAttributes *attr)
{
@@ -99,7 +100,7 @@ _XGetWindowAttributes(
GetResReq(GetWindowAttributes, w, req);
- async_state.attr_seq = dpy->request;
+ async_state.attr_seq = X_DPY_GET_REQUEST(dpy);
async_state.geom_seq = 0;
async_state.attr = attr;
async.next = dpy->async_handlers;
@@ -109,7 +110,7 @@ _XGetWindowAttributes(
GetResReq(GetGeometry, w, req);
- async_state.geom_seq = dpy->request;
+ async_state.geom_seq = X_DPY_GET_REQUEST(dpy);
if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
DeqAsyncHandler(dpy, &async);
diff --git a/nx-X11/lib/src/Host.c b/nx-X11/lib/src/Host.c
index b07c9c312..e2b7d57d7 100644
--- a/nx-X11/lib/src/Host.c
+++ b/nx-X11/lib/src/Host.c
@@ -90,11 +90,11 @@ changehost (Display *dpy, XHostAddress *host, BYTE mode)
req->hostLength = addrlen;
if (siAddr) {
char *dest = (char *) NEXTPTR(req,xChangeHostsReq);
- memcpy(dest, siAddr->type, siAddr->typelength);
+ memcpy(dest, siAddr->type, (size_t) siAddr->typelength);
dest[siAddr->typelength] = '\0';
- memcpy(dest + siAddr->typelength + 1,siAddr->value,siAddr->valuelength);
+ memcpy(dest + siAddr->typelength + 1,siAddr->value,(size_t) siAddr->valuelength);
} else {
- memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, addrlen);
+ memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, (size_t) addrlen);
}
UnlockDisplay(dpy);
SyncHandle();
diff --git a/nx-X11/lib/src/ImUtil.c b/nx-X11/lib/src/ImUtil.c
index 79ba80ecc..5e41c30ff 100644
--- a/nx-X11/lib/src/ImUtil.c
+++ b/nx-X11/lib/src/ImUtil.c
@@ -265,7 +265,7 @@ static void _putbits(
* valid, and reinit the functions if not.
*/
void _XInitImageFuncPtrs (
- register XImage *image)
+ XImage *image)
{
image->f.create_image = XCreateImage;
image->f.destroy_image = _XDestroyImage;
@@ -914,9 +914,9 @@ static XImage *_XSubImage (
int _XSetImage(
XImage *srcimg,
- register XImage *dstimg,
- register int x,
- register int y)
+ XImage *dstimg,
+ int x,
+ int y)
{
register unsigned long pixel;
register int row, col;
diff --git a/nx-X11/lib/src/IntAtom.c b/nx-X11/lib/src/IntAtom.c
index 3042b65dd..0dcb9eccc 100644
--- a/nx-X11/lib/src/IntAtom.c
+++ b/nx-X11/lib/src/IntAtom.c
@@ -50,6 +50,7 @@ _XFreeAtomTable(Display *dpy)
Xfree(e);
}
Xfree(dpy->atoms);
+ dpy->atoms = NULL;
}
}
@@ -188,8 +189,8 @@ XInternAtom (
}
typedef struct {
- unsigned long start_seq;
- unsigned long stop_seq;
+ uint64_t start_seq;
+ uint64_t stop_seq;
char **names;
Atom *atoms;
int count;
@@ -208,10 +209,12 @@ Bool _XIntAtomHandler(
register int i, idx = 0;
xInternAtomReply replbuf;
register xInternAtomReply *repl;
+ uint64_t last_request_read = X_DPY_GET_LAST_REQUEST_READ(dpy);
state = (_XIntAtomState *)data;
- if (dpy->last_request_read < state->start_seq ||
- dpy->last_request_read > state->stop_seq)
+
+ if (last_request_read < state->start_seq ||
+ last_request_read > state->stop_seq)
return False;
for (i = 0; i < state->count; i++) {
if (state->atoms[i] & 0x80000000) {
@@ -252,7 +255,7 @@ XInternAtoms (
xInternAtomReply rep;
LockDisplay(dpy);
- async_state.start_seq = dpy->request + 1;
+ async_state.start_seq = X_DPY_GET_REQUEST(dpy) + 1;
async_state.atoms = atoms_return;
async_state.names = names;
async_state.count = count - 1;
@@ -266,7 +269,7 @@ XInternAtoms (
&sig, &idx, &n))) {
missed = i;
atoms_return[i] = ~((Atom)idx);
- async_state.stop_seq = dpy->request;
+ async_state.stop_seq = X_DPY_GET_REQUEST(dpy);
}
}
if (missed >= 0) {
diff --git a/nx-X11/lib/src/KeyBind.c b/nx-X11/lib/src/KeyBind.c
index acaf7fd8f..e9aa8f071 100644
--- a/nx-X11/lib/src/KeyBind.c
+++ b/nx-X11/lib/src/KeyBind.c
@@ -466,6 +466,8 @@ UCSConvertCase( register unsigned code,
*upper = 0x0178;
else if (code == 0x00b5) /* micro sign */
*upper = 0x039c;
+ else if (code == 0x00df) /* ssharp */
+ *upper = 0x1e9e;
return;
}
@@ -595,6 +597,8 @@ UCSConvertCase( register unsigned code,
}
else if (code == 0x1e9b)
*upper = 0x1e60;
+ else if (code == 0x1e9e)
+ *lower = 0x00df; /* ssharp */
}
/* Greek Extended, U+1F00 to U+1FFF */
@@ -737,8 +741,9 @@ XConvertCase(
*upper -= (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
else if (sym >= XK_Greek_ALPHA && sym <= XK_Greek_OMEGA)
*lower += (XK_Greek_alpha - XK_Greek_ALPHA);
- else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega &&
- sym != XK_Greek_finalsmallsigma)
+ else if (sym == XK_Greek_finalsmallsigma)
+ *upper = XK_Greek_SIGMA;
+ else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega)
*upper -= (XK_Greek_alpha - XK_Greek_ALPHA);
break;
case 0x13: /* Latin 9 */
@@ -832,7 +837,7 @@ _XTranslateKeySym(
if (((modifiers & AllMods) == p->state) && (symbol == p->key)) {
length = p->len;
if (length > nbytes) length = nbytes;
- memcpy (buffer, p->string, length);
+ memcpy (buffer, p->string, (size_t) length);
return length;
}
}
@@ -906,6 +911,7 @@ _XFreeKeyBindings(
Xfree(p->modifiers);
Xfree(p);
}
+ dpy->key_bindings = NULL;
}
int
@@ -941,9 +947,9 @@ XRebindKeysym (
dpy->key_bindings = p;
dpy->free_funcs->key_bindings = _XFreeKeyBindings;
p->next = tmp; /* chain onto list */
- memcpy (p->string, str, nbytes);
+ memcpy (p->string, str, (size_t) nbytes);
p->len = nbytes;
- memcpy ((char *) p->modifiers, (char *) mlist, nb);
+ memcpy ((char *) p->modifiers, (char *) mlist, (size_t) nb);
p->key = keysym;
p->mlen = nm;
ComputeMaskFromKeytrans(dpy, p);
diff --git a/nx-X11/lib/src/KeysymStr.c b/nx-X11/lib/src/KeysymStr.c
index ba6c8450a..a23bd2798 100644
--- a/nx-X11/lib/src/KeysymStr.c
+++ b/nx-X11/lib/src/KeysymStr.c
@@ -109,7 +109,7 @@ char *XKeysymToString(KeySym ks)
snprintf(buf, sizeof(buf), "%lX", ks);
resval.addr = (XPointer)buf;
- resval.size = strlen(buf) + 1;
+ resval.size = (unsigned)strlen(buf) + 1;
data.name = (char *)NULL;
data.type = XrmPermStringToQuark("String");
data.value = &resval;
diff --git a/nx-X11/lib/src/LiICmaps.c b/nx-X11/lib/src/LiICmaps.c
index 45a2f2fd3..590b1bb07 100644
--- a/nx-X11/lib/src/LiICmaps.c
+++ b/nx-X11/lib/src/LiICmaps.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
Colormap *XListInstalledColormaps(
register Display *dpy,
@@ -50,8 +51,7 @@ Colormap *XListInstalledColormaps(
}
if (rep.nColormaps) {
- nbytes = rep.nColormaps * sizeof(Colormap);
- cmaps = Xmalloc(nbytes);
+ cmaps = Xmallocarray(rep.nColormaps, sizeof(Colormap));
if (! cmaps) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
diff --git a/nx-X11/lib/src/LiProps.c b/nx-X11/lib/src/LiProps.c
index d9c746563..411fff626 100644
--- a/nx-X11/lib/src/LiProps.c
+++ b/nx-X11/lib/src/LiProps.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
Atom *XListProperties(
register Display *dpy,
@@ -49,8 +50,7 @@ Atom *XListProperties(
}
if (rep.nProperties) {
- nbytes = rep.nProperties * sizeof(Atom);
- properties = Xmalloc (nbytes);
+ properties = Xmallocarray (rep.nProperties, sizeof(Atom));
if (! properties) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
diff --git a/nx-X11/lib/src/ListExt.c b/nx-X11/lib/src/ListExt.c
index a795041d0..69ae53da0 100644
--- a/nx-X11/lib/src/ListExt.c
+++ b/nx-X11/lib/src/ListExt.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
char **XListExtensions(
@@ -54,7 +55,7 @@ char **XListExtensions(
}
if (rep.nExtensions) {
- list = Xmalloc (rep.nExtensions * sizeof (char *));
+ list = Xmallocarray (rep.nExtensions, sizeof (char *));
if (rep.length > 0 && rep.length < (INT_MAX >> 2)) {
rlen = rep.length << 2;
ch = Xmalloc (rlen + 1);
diff --git a/nx-X11/lib/src/LoadFont.c b/nx-X11/lib/src/LoadFont.c
index f547976ba..2a18e52c2 100644
--- a/nx-X11/lib/src/LoadFont.c
+++ b/nx-X11/lib/src/LoadFont.c
@@ -27,6 +27,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xlibint.h"
Font
@@ -38,12 +39,15 @@ XLoadFont (
Font fid;
register xOpenFontReq *req;
+ if (name != NULL && strlen(name) >= USHRT_MAX)
+ return (0);
+
if (_XF86LoadQueryLocaleFont(dpy, name, (XFontStruct **)0, &fid))
return fid;
LockDisplay(dpy);
GetReq(OpenFont, req);
- nbytes = req->nbytes = name ? strlen(name) : 0;
+ nbytes = req->nbytes = name ? (CARD16) strlen(name) : 0;
req->fid = fid = XAllocID(dpy);
req->length += (nbytes+3)>>2;
Data (dpy, name, nbytes);
diff --git a/nx-X11/lib/src/LookupCol.c b/nx-X11/lib/src/LookupCol.c
index f7f969f56..3b53bf878 100644
--- a/nx-X11/lib/src/LookupCol.c
+++ b/nx-X11/lib/src/LookupCol.c
@@ -27,6 +27,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include "Xlibint.h"
#include "Xcmsint.h"
@@ -40,12 +41,17 @@ XLookupColor (
XColor *def,
XColor *scr)
{
- register int n;
+ register size_t n;
xLookupColorReply reply;
register xLookupColorReq *req;
XcmsCCC ccc;
XcmsColor cmsColor_exact;
+ if (spec == NULL)
+ return 0;
+ n = strlen (spec);
+ if (n >= USHRT_MAX)
+ return 0;
#ifdef XCMS
/*
* Let's Attempt to use Xcms and i18n approach to Parse Color
@@ -77,8 +83,6 @@ XLookupColor (
* Xcms and i18n methods failed, so lets pass it to the server
* for parsing.
*/
-
- n = strlen (spec);
LockDisplay(dpy);
GetReq (LookupColor, req);
req->cmap = cmap;
diff --git a/nx-X11/lib/src/Makefile.am b/nx-X11/lib/src/Makefile.am
index 016dbc5cf..984109dd0 100644
--- a/nx-X11/lib/src/Makefile.am
+++ b/nx-X11/lib/src/Makefile.am
@@ -250,6 +250,7 @@ libNX_X11_la_SOURCES = \
QuTree.c \
RaiseWin.c \
RdBitF.c \
+ reallocarray.c \
RecolorC.c \
ReconfWin.c \
ReconfWM.c \
diff --git a/nx-X11/lib/src/ModMap.c b/nx-X11/lib/src/ModMap.c
index ca15dde25..4ceb07f38 100644
--- a/nx-X11/lib/src/ModMap.c
+++ b/nx-X11/lib/src/ModMap.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
XModifierKeymap *
@@ -100,7 +101,7 @@ XNewModifiermap(int keyspermodifier)
if (res) {
res->max_keypermod = keyspermodifier;
res->modifiermap = (keyspermodifier > 0 ?
- Xmalloc(8 * keyspermodifier)
+ Xmallocarray(keyspermodifier, 8)
: (KeyCode *) NULL);
if (keyspermodifier && (res->modifiermap == NULL)) {
Xfree(res);
diff --git a/nx-X11/lib/src/OpenDis.c b/nx-X11/lib/src/OpenDis.c
index 965924650..6d487e010 100644
--- a/nx-X11/lib/src/OpenDis.c
+++ b/nx-X11/lib/src/OpenDis.c
@@ -180,37 +180,21 @@ XOpenDisplay (
return(NULL);
}
+ if ((dpy->display_name = strdup(display_name)) == NULL) {
+ OutOfMemory(dpy, setup);
+ return(NULL);
+ }
+
/*
* Call the Connect routine to get the transport connection object.
- * If NULL is returned, the connection failed. The connect routine
- * will set fullname to point to the expanded name.
+ * If NULL is returned, the connection failed.
*/
#if USE_XCB
- if(!_XConnectXCB(dpy, display, &fullname, &iscreen)) {
- /* Try falling back on other transports if no transport specified */
- const char *slash = strrchr(display_name, '/');
- if(slash == NULL) {
- const char *protocols[] = {"local", "unix", "tcp", "inet6", "inet", NULL};
- const char **s;
- size_t buf_size = strlen(display_name) + 7; // max strlen + 2 (null + /)
- char *buf = Xmalloc(buf_size * sizeof(char));
-
- if(buf) {
- for(s = protocols; buf && *s; s++) {
- snprintf(buf, buf_size, "%s/%s", *s, display_name);
- if(_XConnectXCB(dpy, buf, &fullname, &iscreen))
- goto fallback_success;
- }
- Xfree(buf);
- }
- }
-
- dpy->display_name = fullname;
- OutOfMemory(dpy, NULL);
+ if(!_XConnectXCB(dpy, display, &iscreen)) {
+ OutOfMemory(dpy, setup);
return NULL;
}
-fallback_success:
#else /* !USE_XCB */
if ((dpy->trans_conn = _X11TransConnectDisplay (
display_name, &fullname, &idisplay,
@@ -224,7 +208,7 @@ fallback_success:
dpy->fd = _X11TransGetConnectionNumber (dpy->trans_conn);
#endif /* USE_XCB */
-#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
fprintf(stderr, "\nXOpenDisplay: Connected display with dpy->fd = [%d].\n", dpy->fd);
#endif
/* Initialize as much of the display structure as we can.
@@ -285,6 +269,7 @@ fallback_success:
dpy->flushes = NULL;
dpy->xcmisc_opcode = 0;
dpy->xkb_info = NULL;
+ dpy->exit_handler_data = NULL;
/*
* Setup other information in this display structure.
@@ -294,10 +279,12 @@ fallback_success:
dpy->idlist_alloc = _XAllocIDs;
dpy->synchandler = NULL;
dpy->savedsynchandler = NULL;
- dpy->request = 0;
- dpy->last_request_read = 0;
+ X_DPY_SET_REQUEST(dpy, 0);
+ X_DPY_SET_LAST_REQUEST_READ(dpy, 0);
dpy->default_screen = iscreen; /* Value returned by ConnectDisplay */
dpy->last_req = (char *)&_dummy_request;
+ dpy->error_threads = NULL;
+ dpy->exit_handler = _XDefaultIOErrorExit;
/* Initialize the display lock */
if (InitDisplayLock(dpy) != 0) {
@@ -330,7 +317,7 @@ fallback_success:
conn_buf_size = 1024 * strtol(xlib_buffer_size, NULL, 10);
if (conn_buf_size < XLIBMINBUFSIZE)
conn_buf_size = XLIBMINBUFSIZE;
-#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
fprintf (stderr, "Xlib: Running with XLIBBUFFERSIZE [%d] XLIBMINBUFSIZE [%d] "
"buffer size [%ld].\n", XLIBDEFAULTBUFSIZE, XLIBMINBUFSIZE, conn_buf_size);
#endif
@@ -533,7 +520,7 @@ fallback_success:
}
u.setup = (xConnSetup *) (((char *) u.setup) + sz_xConnSetup);
- (void) strncpy(dpy->vendor, u.vendor, vendorlen);
+ (void) strncpy(dpy->vendor, u.vendor, (size_t) vendorlen);
dpy->vendor[vendorlen] = '\0';
vendorlen = (vendorlen + 3) & ~3; /* round up */
u.vendor += vendorlen;
diff --git a/nx-X11/lib/src/ParseCol.c b/nx-X11/lib/src/ParseCol.c
index e997b1b8c..fcf906929 100644
--- a/nx-X11/lib/src/ParseCol.c
+++ b/nx-X11/lib/src/ParseCol.c
@@ -27,6 +27,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include "Xlibint.h"
#include "Xcmsint.h"
@@ -39,7 +40,7 @@ XParseColor (
_Xconst char *spec,
XColor *def)
{
- register int n, i;
+ register size_t n, i;
int r, g, b;
char c;
XcmsCCC ccc;
@@ -47,6 +48,8 @@ XParseColor (
if (!spec) return(0);
n = strlen (spec);
+ if (n >= USHRT_MAX)
+ return(0);
if (*spec == '#') {
/*
* RGB
@@ -61,7 +64,7 @@ XParseColor (
r = g;
g = b;
b = 0;
- for (i = n; --i >= 0; ) {
+ for (i = 0; i < n; i++) {
c = *spec++;
b <<= 4;
if (c >= '0' && c <= '9')
@@ -119,7 +122,7 @@ XParseColor (
LockDisplay(dpy);
GetReq (LookupColor, req);
req->cmap = cmap;
- req->nbytes = n = strlen(spec);
+ req->nbytes = (CARD16) (n = strlen(spec));
req->length += (n + 3) >> 2;
Data (dpy, spec, (long)n);
if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
diff --git a/nx-X11/lib/src/PixFormats.c b/nx-X11/lib/src/PixFormats.c
index 6d9f64d2c..f9fd3e44a 100644
--- a/nx-X11/lib/src/PixFormats.c
+++ b/nx-X11/lib/src/PixFormats.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <stdio.h>
/*
@@ -39,7 +40,7 @@ XPixmapFormatValues *XListPixmapFormats (
int *count) /* RETURN */
{
XPixmapFormatValues *formats =
- Xmalloc(dpy->nformats * sizeof (XPixmapFormatValues));
+ Xmallocarray(dpy->nformats, sizeof (XPixmapFormatValues));
if (formats) {
register int i;
diff --git a/nx-X11/lib/src/PolyReg.c b/nx-X11/lib/src/PolyReg.c
index cb30f8422..ce2138cfe 100644
--- a/nx-X11/lib/src/PolyReg.c
+++ b/nx-X11/lib/src/PolyReg.c
@@ -55,6 +55,7 @@ SOFTWARE.
#include "Xutil.h"
#include <nx-X11/Xregion.h>
#include "poly.h"
+#include "reallocarray.h"
/*
* InsertEdgeInET
@@ -409,7 +410,7 @@ static int PtsToRegion(
numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1;
- if (!(reg->rects = Xrealloc(reg->rects, sizeof(BOX) * numRects))) {
+ if (!(reg->rects = Xreallocarray(reg->rects, numRects, sizeof(BOX)))) {
Xfree(prevRects);
return(0);
}
@@ -519,7 +520,7 @@ XPolygonRegion(
if (Count < 2) return region;
- if (! (pETEs = Xmalloc(sizeof(EdgeTableEntry) * Count))) {
+ if (! (pETEs = Xmallocarray(Count, sizeof(EdgeTableEntry)))) {
XDestroyRegion(region);
return (Region) NULL;
}
diff --git a/nx-X11/lib/src/PolyTxt.c b/nx-X11/lib/src/PolyTxt.c
index 471383b57..5c0046614 100644
--- a/nx-X11/lib/src/PolyTxt.c
+++ b/nx-X11/lib/src/PolyTxt.c
@@ -197,7 +197,7 @@ XDrawText(
*(tbuf+1) = 0; /* elt->delta */
}
*tbuf = PartialNChars; /* elt->len */
- memcpy (tbuf+2 , CharacterOffset, PartialNChars);
+ memcpy (tbuf+2 , CharacterOffset, (size_t) PartialNChars);
}
}
item++;
diff --git a/nx-X11/lib/src/PutBEvent.c b/nx-X11/lib/src/PutBEvent.c
index 1768e032c..0f9df3429 100644
--- a/nx-X11/lib/src/PutBEvent.c
+++ b/nx-X11/lib/src/PutBEvent.c
@@ -34,8 +34,8 @@ from The Open Group.
int
_XPutBackEvent (
- register Display *dpy,
- register XEvent *event)
+ Display *dpy,
+ XEvent *event)
{
register _XQEvent *qelt;
XEvent store = *event;
diff --git a/nx-X11/lib/src/PutImage.c b/nx-X11/lib/src/PutImage.c
index daf172cf0..b3a1a96df 100644
--- a/nx-X11/lib/src/PutImage.c
+++ b/nx-X11/lib/src/PutImage.c
@@ -32,6 +32,7 @@ in this Software without prior written authorization from The Open Group.
#include <stdio.h>
#include "Cr.h"
#include "ImUtil.h"
+#include "reallocarray.h"
#if defined(__STDC__) && ((defined(sun) && defined(SVR4)) || defined(WIN32))
#define RConst /**/
@@ -114,8 +115,8 @@ static unsigned char const _reverse_nibs[0x100] = {
int
_XReverse_Bytes(
- register unsigned char *bpt,
- register int nb)
+ unsigned char *bpt,
+ int nb)
{
do {
*bpt = _reverse_byte[*bpt];
@@ -598,7 +599,7 @@ static int const HalfOrderWord[12] = {
#define UnGetReq(name)\
dpy->bufptr -= SIZEOF(x##name##Req);\
- dpy->request--
+ X_DPY_REQUEST_DECREMENT(dpy)
static void
SendXYImage(
@@ -767,7 +768,7 @@ SendZImage(
(req_yoffset * image->bytes_per_line) +
((req_xoffset * image->bits_per_pixel) >> 3);
if ((image->bits_per_pixel == 4) && ((unsigned int) req_xoffset & 0x01)) {
- if (! (shifted_src = Xmalloc(req->height * image->bytes_per_line))) {
+ if (! (shifted_src = Xmallocarray(req->height, image->bytes_per_line))) {
UnGetReq(PutImage);
return;
}
@@ -987,7 +988,7 @@ XPutImage (
img.bits_per_pixel = dest_bits_per_pixel;
img.bytes_per_line = ROUNDUP((dest_bits_per_pixel * width),
dest_scanline_pad) >> 3;
- img.data = Xmalloc(img.bytes_per_line * height);
+ img.data = Xmallocarray(height, img.bytes_per_line);
if (img.data == NULL)
return 0;
_XInitImageFuncPtrs(&img);
diff --git a/nx-X11/lib/src/QuColors.c b/nx-X11/lib/src/QuColors.c
index 0b9bc508f..10cf18257 100644
--- a/nx-X11/lib/src/QuColors.c
+++ b/nx-X11/lib/src/QuColors.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
static void
_XQueryColors(
@@ -50,9 +51,9 @@ _XQueryColors(
/* XXX this isn't very efficient */
if (_XReply(dpy, (xReply *) &rep, 0, xFalse) != 0) {
- unsigned long nbytes = (long) ncolors * SIZEOF(xrgb);
- xrgb *color = Xmalloc(nbytes);
+ xrgb *color = Xmallocarray(ncolors, sizeof(xrgb));
if (color != NULL) {
+ unsigned long nbytes = (long) ncolors * SIZEOF(xrgb);
_XRead(dpy, (char *) color, nbytes);
diff --git a/nx-X11/lib/src/QuExt.c b/nx-X11/lib/src/QuExt.c
index 4e230e776..68c174662 100644
--- a/nx-X11/lib/src/QuExt.c
+++ b/nx-X11/lib/src/QuExt.c
@@ -27,6 +27,8 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
+#include <stdbool.h>
#include "Xlibint.h"
Bool
@@ -40,9 +42,12 @@ XQueryExtension(
xQueryExtensionReply rep;
register xQueryExtensionReq *req;
+ if (name != NULL && strlen(name) >= USHRT_MAX)
+ return false;
+
LockDisplay(dpy);
GetReq(QueryExtension, req);
- req->nbytes = name ? strlen(name) : 0;
+ req->nbytes = name ? (CARD16) strlen(name) : 0;
req->length += (req->nbytes+(unsigned)3)>>2;
_XSend(dpy, name, (long)req->nbytes);
(void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
diff --git a/nx-X11/lib/src/QuTree.c b/nx-X11/lib/src/QuTree.c
index 8da2ae261..9ceef781a 100644
--- a/nx-X11/lib/src/QuTree.c
+++ b/nx-X11/lib/src/QuTree.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
Status XQueryTree (
register Display *dpy,
@@ -51,8 +52,7 @@ Status XQueryTree (
*children = (Window *) NULL;
if (rep.nChildren != 0) {
- nbytes = rep.nChildren * sizeof(Window);
- *children = Xmalloc(nbytes);
+ *children = Xmallocarray(rep.nChildren, sizeof(Window));
if (! *children) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
diff --git a/nx-X11/lib/src/Quarks.c b/nx-X11/lib/src/Quarks.c
index 0e702d566..8e595ca7f 100644
--- a/nx-X11/lib/src/Quarks.c
+++ b/nx-X11/lib/src/Quarks.c
@@ -55,6 +55,7 @@ from The Open Group.
#include "Xlibint.h"
#include <nx-X11/Xresource.h>
#include "Xresinternal.h"
+#include "reallocarray.h"
/* Not cost effective, at least for vanilla MIT clients */
/* #define PERMQ */
@@ -62,7 +63,7 @@ from The Open Group.
#ifdef PERMQ
typedef unsigned char Bits;
#endif
-typedef unsigned long Entry; /* dont confuse with EntryRec from Xintatom.h */
+typedef unsigned long Entry; /* don't confuse with EntryRec from Xintatom.h */
static XrmQuark nextQuark = 1; /* next available quark number */
static unsigned long quarkMask = 0;
@@ -88,7 +89,7 @@ static XrmQuark nextUniq = -1; /* next quark from XrmUniqueQuark */
#define STRQUANTSIZE (sizeof(XrmString) * (QUANTUMMASK + 1))
#ifdef PERMQ
#define QUANTSIZE (STRQUANTSIZE + \
- (sizeof(Bits) * ((QUANTUMMASK + 1) >> 3)))
+ (sizeof(Bits) * ((QUANTUMMASK + 1) >> 3))
#else
#define QUANTSIZE STRQUANTSIZE
#endif
@@ -242,7 +243,6 @@ _XrmInternalStringToQuark(
register XrmQuark q;
register Entry entry;
register int idx, rehash;
- register int i;
register char *s1, *s2;
char *new;
@@ -257,10 +257,11 @@ _XrmInternalStringToQuark(
goto nomatch;
q = (entry >> QUARKSHIFT) & QUARKMASK;
}
- for (i = len, s1 = (char *)name, s2 = NAME(q); --i >= 0; ) {
- if (*s1++ != *s2++)
+ s2 = NAME(q);
+ if(memcmp((char *)name, s2, len) != 0) {
goto nomatch;
}
+ s2 += len;
if (*s2) {
nomatch: if (!rehash)
rehash = REHASHVAL(sig);
@@ -288,15 +289,15 @@ nomatch: if (!rehash)
q = nextQuark;
if (!(q & QUANTUMMASK)) {
if (!(q & CHUNKMASK)) {
- if (!(new = Xrealloc(stringTable,
- sizeof(XrmString *) *
- ((q >> QUANTUMSHIFT) + CHUNKPER))))
+ if (!(new = Xreallocarray(stringTable,
+ (q >> QUANTUMSHIFT) + CHUNKPER,
+ sizeof(XrmString *))))
goto fail;
stringTable = (XrmString **)new;
#ifdef PERMQ
- if (!(new = Xrealloc(permTable,
- sizeof(Bits *) *
- ((q >> QUANTUMSHIFT) + CHUNKPER))))
+ if (!(new = Xreallocarray(permTable,
+ (q >> QUANTUMSHIFT) + CHUNKPER,
+ sizeof(Bits *))))
goto fail;
permTable = (Bits **)new;
#endif
@@ -318,9 +319,9 @@ nomatch: if (!rehash)
#endif
if (!name)
goto fail;
- for (i = len, s1 = (char *)name; --i >= 0; )
- *s1++ = *s2++;
- *s1++ = '\0';
+ s1 = (char*)name;
+ memcpy(s1, s2, (size_t)len);
+ s1[len] = '\0';
#ifdef PERMQ
CLEARPERM(q);
}
@@ -397,7 +398,7 @@ XrmString XrmQuarkToString(register XrmQuark quark)
else {
#ifdef PERMQ
/* We have to mark the quark as permanent, since the caller might hold
- * onto the string pointer forver.
+ * onto the string pointer forever.
*/
SETPERM(quark);
#endif
diff --git a/nx-X11/lib/src/RdBitF.c b/nx-X11/lib/src/RdBitF.c
index 319a0ee0b..d34aafb24 100644
--- a/nx-X11/lib/src/RdBitF.c
+++ b/nx-X11/lib/src/RdBitF.c
@@ -49,7 +49,7 @@ from The Open Group.
#include "Xutil.h"
#include <stdio.h>
#include <ctype.h>
-
+#include "reallocarray.h"
#define MAX_SIZE 255
@@ -187,10 +187,10 @@ XReadBitmapFileData (
bytes_per_line = (ww+7)/8 + padding;
- size = bytes_per_line * hh;
- bits = Xmalloc (size);
+ bits = Xmallocarray (hh, bytes_per_line);
if (!bits)
RETURN (BitmapNoMemory);
+ size = bytes_per_line * hh;
if (version10p) {
unsigned char *ptr;
diff --git a/nx-X11/lib/src/Region.c b/nx-X11/lib/src/Region.c
index 28fa3e416..c5b6067f7 100644
--- a/nx-X11/lib/src/Region.c
+++ b/nx-X11/lib/src/Region.c
@@ -77,6 +77,7 @@ SOFTWARE.
#include "Xutil.h"
#include <nx-X11/Xregion.h>
#include "poly.h"
+#include "reallocarray.h"
#ifdef DEBUG
#include <stdio.h>
@@ -521,8 +522,8 @@ miRegionCopy(
{
BOX *prevRects = dstrgn->rects;
- dstrgn->rects = Xrealloc(dstrgn->rects,
- rgn->numRects * (sizeof(BOX)));
+ dstrgn->rects = Xreallocarray(dstrgn->rects,
+ rgn->numRects, sizeof(BOX));
if (! dstrgn->rects) {
Xfree(prevRects);
dstrgn->size = 0;
@@ -790,7 +791,7 @@ miRegionOp(
*/
newReg->size = max(reg1->numRects,reg2->numRects) * 2;
- if (! (newReg->rects = Xmalloc (sizeof(BoxRec) * newReg->size))) {
+ if (! (newReg->rects = Xmallocarray (newReg->size, sizeof(BoxRec)))) {
newReg->size = 0;
return;
}
@@ -980,8 +981,8 @@ miRegionOp(
if (REGION_NOT_EMPTY(newReg))
{
BoxPtr prev_rects = newReg->rects;
- newReg->rects = Xrealloc (newReg->rects,
- sizeof(BoxRec) * newReg->numRects);
+ newReg->rects = Xreallocarray (newReg->rects,
+ newReg->numRects, sizeof(BoxRec));
if (! newReg->rects)
newReg->rects = prev_rects;
else
@@ -1303,7 +1304,7 @@ miSubtractO (
else if (r2->x1 <= x1)
{
/*
- * Subtrahend preceeds minuend: nuke left edge of minuend.
+ * Subtrahend precedes minuend: nuke left edge of minuend.
*/
x1 = r2->x2;
if (x1 >= r1->x2)
diff --git a/nx-X11/lib/src/RegstFlt.c b/nx-X11/lib/src/RegstFlt.c
index 077ea424c..407ae667d 100644
--- a/nx-X11/lib/src/RegstFlt.c
+++ b/nx-X11/lib/src/RegstFlt.c
@@ -68,6 +68,7 @@ _XFreeIMFilters(
display->im_filters = fl->next;
Xfree(fl);
}
+ display->im_filters = NULL;
}
/*
diff --git a/nx-X11/lib/src/SetCRects.c b/nx-X11/lib/src/SetCRects.c
index c7ad3fcf2..b18c449a6 100644
--- a/nx-X11/lib/src/SetCRects.c
+++ b/nx-X11/lib/src/SetCRects.c
@@ -31,7 +31,7 @@ in this Software without prior written authorization from The Open Group.
/* can only call when display is locked. */
void _XSetClipRectangles (
- register Display *dpy,
+ Display *dpy,
GC gc,
int clip_x_origin, int clip_y_origin,
XRectangle *rectangles,
diff --git a/nx-X11/lib/src/SetFPath.c b/nx-X11/lib/src/SetFPath.c
index 60aaef01e..6ac546f7b 100644
--- a/nx-X11/lib/src/SetFPath.c
+++ b/nx-X11/lib/src/SetFPath.c
@@ -27,6 +27,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xlibint.h"
#define safestrlen(s) ((s) ? strlen(s) : 0)
@@ -37,7 +38,7 @@ XSetFontPath (
char **directories,
int ndirs)
{
- register int n = 0;
+ register size_t n = 0;
register int i;
register int nbytes;
char *p;
@@ -48,7 +49,12 @@ XSetFontPath (
GetReq (SetFontPath, req);
req->nFonts = ndirs;
for (i = 0; i < ndirs; i++) {
- n += safestrlen (directories[i]) + 1;
+ n = n + (safestrlen (directories[i]) + 1);
+ if (n >= USHRT_MAX) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
}
nbytes = (n + 3) & ~3;
req->length += nbytes >> 2;
@@ -59,7 +65,7 @@ XSetFontPath (
char *tmp = p;
for (i = 0; i < ndirs; i++) {
- register int length = safestrlen (directories[i]);
+ size_t length = safestrlen (directories[i]);
*p = length;
memcpy (p + 1, directories[i], length);
p += length + 1;
diff --git a/nx-X11/lib/src/SetHints.c b/nx-X11/lib/src/SetHints.c
index db5e7527e..3997b96c3 100644
--- a/nx-X11/lib/src/SetHints.c
+++ b/nx-X11/lib/src/SetHints.c
@@ -49,11 +49,13 @@ SOFTWARE.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include <nx-X11/Xlibint.h>
#include <nx-X11/Xutil.h>
#include "Xatomtype.h"
#include <nx-X11/Xatom.h>
#include <nx-X11/Xos.h>
+#include "reallocarray.h"
#define safestrlen(s) ((s) ? strlen(s) : 0)
@@ -181,10 +183,8 @@ XSetIconSizes (
{
register int i;
xPropIconSize *pp, *prop;
-#define size_of_the_real_thing sizeof /* avoid grepping screwups */
- unsigned nbytes = count * size_of_the_real_thing(xPropIconSize);
-#undef size_of_the_real_thing
- if ((prop = pp = Xmalloc (nbytes))) {
+
+ if ((prop = pp = Xmallocarray (count, sizeof(xPropIconSize)))) {
for (i = 0; i < count; i++) {
pp->minWidth = list->min_width;
pp->minHeight = list->min_height;
@@ -215,6 +215,8 @@ XSetCommand (
register char *buf, *bp;
for (i = 0, nbytes = 0; i < argc; i++) {
nbytes += safestrlen(argv[i]) + 1;
+ if (nbytes >= USHRT_MAX)
+ return 1;
}
if ((bp = buf = Xmalloc(nbytes))) {
/* copy arguments into single buffer */
@@ -257,11 +259,13 @@ XSetStandardProperties (
if (name != NULL) XStoreName (dpy, w, name);
+ if (safestrlen(icon_string) >= USHRT_MAX)
+ return 1;
if (icon_string != NULL) {
XChangeProperty (dpy, w, XA_WM_ICON_NAME, XA_STRING, 8,
PropModeReplace,
(_Xconst unsigned char *)icon_string,
- safestrlen(icon_string));
+ (int)safestrlen(icon_string));
}
if (icon_pixmap != None) {
@@ -299,6 +303,8 @@ XSetClassHint(
len_nm = safestrlen(classhint->res_name);
len_cl = safestrlen(classhint->res_class);
+ if (len_nm + len_cl >= USHRT_MAX)
+ return 1;
if ((class_string = s = Xmalloc(len_nm + len_cl + 2))) {
if (len_nm) {
strcpy(s, classhint->res_name);
diff --git a/nx-X11/lib/src/SetLocale.c b/nx-X11/lib/src/SetLocale.c
index 3bbfd3ee6..3a65ad162 100644
--- a/nx-X11/lib/src/SetLocale.c
+++ b/nx-X11/lib/src/SetLocale.c
@@ -157,7 +157,7 @@ _XlcMapOSLocaleName(
len = end - start;
if (len >= MAXLOCALE)
len = MAXLOCALE - 1;
- strncpy(siname, start, len);
+ strncpy(siname, start, (size_t) len);
*(siname + len) = '\0';
# ifdef WHITEFILL
for (start = siname; start = strchr(start, ' '); )
diff --git a/nx-X11/lib/src/StNColor.c b/nx-X11/lib/src/StNColor.c
index 8b821c3ef..743fd4edc 100644
--- a/nx-X11/lib/src/StNColor.c
+++ b/nx-X11/lib/src/StNColor.c
@@ -27,6 +27,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include "Xlibint.h"
#include "Xcmsint.h"
@@ -46,6 +47,8 @@ int flags) /* DoRed, DoGreen, DoBlue */
XcmsColor cmsColor_exact;
XColor scr_def;
+ if (name != NULL && strlen(name) >= USHRT_MAX)
+ return 0;
#ifdef XCMS
/*
* Let's Attempt to use Xcms approach to Parse Color
@@ -76,7 +79,7 @@ int flags) /* DoRed, DoGreen, DoBlue */
req->cmap = cmap;
req->flags = flags;
req->pixel = pixel;
- req->nbytes = nbytes = strlen(name);
+ req->nbytes = (CARD16) (nbytes = (unsigned) strlen(name));
req->length += (nbytes + 3) >> 2; /* round up to multiple of 4 */
Data(dpy, name, (long)nbytes);
UnlockDisplay(dpy);
diff --git a/nx-X11/lib/src/StName.c b/nx-X11/lib/src/StName.c
index a003a109e..817ce936d 100644
--- a/nx-X11/lib/src/StName.c
+++ b/nx-X11/lib/src/StName.c
@@ -27,6 +27,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include <nx-X11/Xlibint.h>
#include <nx-X11/Xatom.h>
@@ -36,9 +37,11 @@ XStoreName (
Window w,
_Xconst char *name)
{
- return XChangeProperty(dpy, w, XA_WM_NAME, XA_STRING,
+ if (name != NULL && strlen(name) >= USHRT_MAX)
+ return 0;
+ return XChangeProperty(dpy, w, XA_WM_NAME, XA_STRING, /* */
8, PropModeReplace, (_Xconst unsigned char *)name,
- name ? strlen(name) : 0);
+ name ? (int) strlen(name) : 0);
}
int
@@ -47,7 +50,9 @@ XSetIconName (
Window w,
_Xconst char *icon_name)
{
+ if (icon_name != NULL && strlen(icon_name) >= USHRT_MAX)
+ return 0;
return XChangeProperty(dpy, w, XA_WM_ICON_NAME, XA_STRING, 8,
PropModeReplace, (_Xconst unsigned char *)icon_name,
- icon_name ? strlen(icon_name) : 0);
+ icon_name ? (int) strlen(icon_name) : 0);
}
diff --git a/nx-X11/lib/src/Text.c b/nx-X11/lib/src/Text.c
index 223b1cf8b..b3cfd3393 100644
--- a/nx-X11/lib/src/Text.c
+++ b/nx-X11/lib/src/Text.c
@@ -104,7 +104,7 @@ XDrawString(
*(tbuf+1) = 0;
/* memcpy ((char *) (elt + 1), CharacterOffset, PartialNChars);
*/
- memcpy ((char *)tbuf+2, CharacterOffset, PartialNChars);
+ memcpy ((char *)tbuf+2, CharacterOffset, (size_t)PartialNChars);
}
}
diff --git a/nx-X11/lib/src/TextToStr.c b/nx-X11/lib/src/TextToStr.c
index 03f71558b..096ea1b50 100644
--- a/nx-X11/lib/src/TextToStr.c
+++ b/nx-X11/lib/src/TextToStr.c
@@ -31,7 +31,7 @@ in this Software without prior written authorization from The Open Group.
#include <nx-X11/Xlibint.h>
#include <nx-X11/Xatom.h>
#include <nx-X11/Xutil.h>
-
+#include "reallocarray.h"
/*
* XTextPropertyToStringList - set list and count to contain data stored in
@@ -72,7 +72,7 @@ Status XTextPropertyToStringList (
/*
* allocate list and duplicate
*/
- list = Xmalloc (nelements * sizeof (char *));
+ list = Xmallocarray (nelements, sizeof (char *));
if (!list) return False;
start = Xmalloc ((datalen + 1) * sizeof (char)); /* for <NUL> */
diff --git a/nx-X11/lib/src/VisUtil.c b/nx-X11/lib/src/VisUtil.c
index 17ca3631f..c2ea3d109 100644
--- a/nx-X11/lib/src/VisUtil.c
+++ b/nx-X11/lib/src/VisUtil.c
@@ -30,6 +30,8 @@ in this Software without prior written authorization from The Open Group.
#include "Xlibint.h"
#include "Xutil.h"
#include <stdio.h>
+#include "reallocarray.h"
+
/*
* This procedure returns a list of visual information structures
* that match the specified attributes given in the visual information
@@ -75,7 +77,7 @@ XVisualInfo *XGetVisualInfo(
count = 0;
total = 10;
- if (! (vip_base = vip = Xmalloc(sizeof(XVisualInfo) * total))) {
+ if (! (vip_base = vip = Xmallocarray(total, sizeof(XVisualInfo)))) {
UnlockDisplay(dpy);
return (XVisualInfo *) NULL;
}
@@ -131,8 +133,8 @@ XVisualInfo *XGetVisualInfo(
{
XVisualInfo *old_vip_base = vip_base;
total += 10;
- if (! (vip_base = Xrealloc(vip_base,
- sizeof(XVisualInfo) * total))) {
+ if (! (vip_base = Xreallocarray(vip_base, total,
+ sizeof(XVisualInfo)))) {
Xfree(old_vip_base);
UnlockDisplay(dpy);
return (XVisualInfo *) NULL;
diff --git a/nx-X11/lib/src/WMProps.c b/nx-X11/lib/src/WMProps.c
index e77f7ba56..d8ca9caa4 100644
--- a/nx-X11/lib/src/WMProps.c
+++ b/nx-X11/lib/src/WMProps.c
@@ -105,7 +105,7 @@ void XSetWMProperties (
textprop.value = (unsigned char *) hostName;
textprop.encoding = XA_STRING;
textprop.format = 8;
- textprop.nitems = len;
+ textprop.nitems = (unsigned long) len;
XSetWMClientMachine (dpy, w, &textprop);
/* set hints about how geometry and window manager interaction */
@@ -134,6 +134,6 @@ void XSetWMProperties (
if (locale)
XChangeProperty (dpy, w, XInternAtom(dpy, "WM_LOCALE_NAME", False),
XA_STRING, 8, PropModeReplace,
- (unsigned char *)locale, strlen(locale));
+ (unsigned char *)locale, (int) strlen(locale));
}
diff --git a/nx-X11/lib/src/Window.c b/nx-X11/lib/src/Window.c
index 85a28f372..e643f2197 100644
--- a/nx-X11/lib/src/Window.c
+++ b/nx-X11/lib/src/Window.c
@@ -30,10 +30,10 @@ in this Software without prior written authorization from The Open Group.
#include "Xlibint.h"
void _XProcessWindowAttributes (
- register Display *dpy,
+ Display *dpy,
xChangeWindowAttributesReq *req,
- register unsigned long valuemask,
- register XSetWindowAttributes *attributes)
+ unsigned long valuemask,
+ XSetWindowAttributes *attributes)
{
unsigned long values[32];
register unsigned long *value = values;
diff --git a/nx-X11/lib/src/WrBitF.c b/nx-X11/lib/src/WrBitF.c
index 47b47208f..abd42b2e6 100644
--- a/nx-X11/lib/src/WrBitF.c
+++ b/nx-X11/lib/src/WrBitF.c
@@ -33,6 +33,7 @@ from The Open Group.
#include <nx-X11/Xos.h>
#include "Xutil.h"
#include <stdio.h>
+#include "reallocarray.h"
#define ERR_RETURN NULL
@@ -53,7 +54,7 @@ static char *Format_Image(
bytes_per_line = (width+7)/8;
*resultsize = bytes_per_line * height; /* Calculate size of data */
- data = Xmalloc( *resultsize ); /* Get space for data */
+ data = Xmallocarray(bytes_per_line, height); /* Get space for data */
if (!data)
return(ERR_RETURN);
diff --git a/nx-X11/lib/src/XlibAsync.c b/nx-X11/lib/src/XlibAsync.c
index 2e528d8b1..b9a5d90ab 100644
--- a/nx-X11/lib/src/XlibAsync.c
+++ b/nx-X11/lib/src/XlibAsync.c
@@ -57,6 +57,18 @@ from The Open Group.
#include <nx-X11/Xlibint.h>
#include <nx-X11/Xos.h>
+/*
+ * Xlib's _XAsyncErrorState sequence number may wrap in 32bit
+ * and we cannot use 64bit as it's public API.
+ */
+#ifdef LONG64
+#define _XLIB_ASYNC_SEQUENCE_CMP(a,op,b) ((a == 0) || (a op b))
+#else /* !LONG64 */
+#define _XLIB_ASYNC_SEQUENCE_CMP(a,op,b) ((a == 0) || \
+ (((a op b) && (b - a op (UINT32_MAX >> 1))) || \
+ ((b op a) && ((UINT32_MAX >> 1) op a - b))))
+#endif /* !LONG64 */
+
/*ARGSUSED*/
Bool
_XAsyncErrorHandler(
@@ -76,10 +88,8 @@ _XAsyncErrorHandler(
rep->error.majorCode == state->major_opcode) &&
(!state->minor_opcode ||
rep->error.minorCode == state->minor_opcode) &&
- (!state->min_sequence_number ||
- (state->min_sequence_number <= dpy->last_request_read)) &&
- (!state->max_sequence_number ||
- (state->max_sequence_number >= dpy->last_request_read))) {
+ (_XLIB_ASYNC_SEQUENCE_CMP(state->min_sequence_number,<=,dpy->last_request_read)) &&
+ (_XLIB_ASYNC_SEQUENCE_CMP(state->max_sequence_number,>=,dpy->last_request_read))) {
state->last_error_received = rep->error.errorCode;
state->error_count++;
return True;
diff --git a/nx-X11/lib/src/XlibInt.c b/nx-X11/lib/src/XlibInt.c
index bd97ed0bc..491213aeb 100644
--- a/nx-X11/lib/src/XlibInt.c
+++ b/nx-X11/lib/src/XlibInt.c
@@ -64,6 +64,7 @@ from The Open Group.
#endif
#include "Xlibint.h"
#include "Xprivate.h"
+#include "reallocarray.h"
#include <nx-X11/Xpoll.h>
#if !USE_XCB
#include <nx-X11/Xtrans/Xtrans.h>
@@ -75,9 +76,28 @@ from The Open Group.
#include <direct.h>
#endif
+/* Needed for FIONREAD on Solaris */
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
+
+/* Needed for FIONREAD on Cygwin */
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+/* Needed for ioctl() on Solaris */
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#ifdef XTHREADS
#include "locking.h"
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+
/* these pointers get initialized by XInitThreads */
LockInfoPtr _Xglobal_lock = NULL;
void (*_XCreateMutex_fn)(LockInfoPtr) = NULL;
@@ -838,7 +858,7 @@ _XWaitForReadable(
static int sync_hazard(Display *dpy)
{
/*
- * "span" and "hazard" need to be signed such that the ">=" comparision
+ * "span" and "hazard" need to be signed such that the ">=" comparison
* works correctly in the case that hazard is greater than 65525
*/
int64_t span = X_DPY_GET_REQUEST(dpy) - X_DPY_GET_LAST_REQUEST_READ(dpy);
@@ -1625,7 +1645,7 @@ int _XRead(
#ifdef LONG64
void _XRead32(
Display *dpy,
- register long *data,
+ long *data,
long len)
{
register int *buf;
@@ -2477,7 +2497,7 @@ _XRegisterInternalConnection(
new_conni = Xmalloc(sizeof(struct _XConnectionInfo));
if (!new_conni)
return 0;
- new_conni->watch_data = Xmalloc(dpy->watcher_count * sizeof(XPointer));
+ new_conni->watch_data = Xmallocarray(dpy->watcher_count, sizeof(XPointer));
if (!new_conni->watch_data) {
Xfree(new_conni);
return 0;
@@ -2569,7 +2589,7 @@ XInternalConnectionNumbers(
count = 0;
for (info_list=dpy->im_fd_info; info_list; info_list=info_list->next)
count++;
- fd_list = Xmalloc (count * sizeof(int));
+ fd_list = Xmallocarray (count, sizeof(int));
if (!fd_list) {
UnlockDisplay(dpy);
return 0;
@@ -2662,8 +2682,8 @@ XAddConnectionWatch(
/* allocate new watch data */
for (info_list=dpy->im_fd_info; info_list; info_list=info_list->next) {
- wd_array = Xrealloc(info_list->watch_data,
- (dpy->watcher_count + 1) * sizeof(XPointer));
+ wd_array = Xreallocarray(info_list->watch_data,
+ dpy->watcher_count + 1, sizeof(XPointer));
if (!wd_array) {
UnlockDisplay(dpy);
return 0;
@@ -2835,11 +2855,10 @@ _XFreeEventCookies(Display *dpy)
head = (struct stored_event**)&dpy->cookiejar;
DL_FOREACH_SAFE(*head, e, tmp) {
- if (dpy->cookiejar == e)
- dpy->cookiejar = NULL;
XFree(e->ev.data);
XFree(e);
}
+ dpy->cookiejar = NULL;
}
/**
@@ -2861,6 +2880,7 @@ _XStoreEventCookie(Display *dpy, XEvent *event)
if (!add) {
ESET(ENOMEM);
_XIOError(dpy);
+ return;
}
add->ev = *cookie;
DL_APPEND(*head, add);
@@ -2934,10 +2954,8 @@ void _XEnq(
else if ((qelt = Xmalloc(sizeof(_XQEvent))) == NULL) {
/* Malloc call failed! */
ESET(ENOMEM);
- _XIOError(dpy);
-#ifdef NX_TRANS_SOCKET
- return;
-#endif
+ _XIOError(dpy);
+ return;
}
qelt->next = NULL;
@@ -3441,18 +3459,51 @@ _XWireToEvent(
return(True);
}
+static int
+SocketBytesReadable(Display *dpy)
+{
+ int bytes = 0, last_error;
+#ifdef WIN32
+ last_error = WSAGetLastError();
+ ioctlsocket(ConnectionNumber(dpy), FIONREAD, &bytes);
+ WSASetLastError(last_error);
+#else
+ last_error = errno;
+ ioctl(ConnectionNumber(dpy), FIONREAD, &bytes);
+ errno = last_error;
+#endif
+ return bytes;
+}
+
+_X_NORETURN void _XDefaultIOErrorExit(
+ Display *dpy,
+ void *user_data)
+{
+ exit(1);
+ /*NOTREACHED*/
+}
/*
* _XDefaultIOError - Default fatal system error reporting routine. Called
* when an X internal system error is encountered.
*/
-int _XDefaultIOError(
+_X_NORETURN int _XDefaultIOError(
Display *dpy)
{
- if (ECHECK(EPIPE)) {
- (void) fprintf (stderr,
- "X connection to %s broken (explicit kill or server shutdown).\r\n",
- DisplayString (dpy));
+ int killed = ECHECK(EPIPE);
+
+ /*
+ * If the socket was closed on the far end, the final recvmsg in
+ * xcb will have thrown EAGAIN because we're non-blocking. Detect
+ * this to get the more informative error message.
+ */
+ if (ECHECK(EAGAIN) && SocketBytesReadable(dpy) <= 0)
+ killed = True;
+
+ if (killed) {
+ fprintf (stderr,
+ "X connection to %s broken (explicit kill or server shutdown).\r\n",
+ DisplayString (dpy));
} else {
(void) fprintf (stderr,
"XIO: fatal IO error %d (%s) on X server \"%s\"\r\n",
@@ -3666,6 +3717,11 @@ int _XError (
if (_XErrorFunction != NULL) {
int rtn_val;
#ifdef XTHREADS
+ struct _XErrorThreadInfo thread_info = {
+ .error_thread = xthread_self(),
+ .next = dpy->error_threads
+ }, **prev;
+ dpy->error_threads = &thread_info;
if (dpy->lock)
(*dpy->lock->user_lock_display)(dpy);
UnlockDisplay(dpy);
@@ -3675,6 +3731,11 @@ int _XError (
LockDisplay(dpy);
if (dpy->lock)
(*dpy->lock->user_unlock_display)(dpy);
+
+ /* unlink thread_info from the list */
+ for (prev = &dpy->error_threads; *prev != &thread_info; prev = &(*prev)->next)
+ ;
+ *prev = thread_info.next;
#endif
return rtn_val;
} else {
@@ -3689,6 +3750,9 @@ int
_XIOError (
Display *dpy)
{
+ XIOErrorExitHandler exit_handler;
+ void *exit_handler_data;
+
dpy->flags |= XlibDisplayIOError;
#ifdef WIN32
errno = WSAGetLastError();
@@ -3702,6 +3766,8 @@ _XIOError (
if (dpy->lock)
(*dpy->lock->user_lock_display)(dpy);
#endif
+ exit_handler = dpy->exit_handler;
+ exit_handler_data = dpy->exit_handler_data;
UnlockDisplay(dpy);
if (_XIOErrorFunction != NULL)
@@ -3721,6 +3787,7 @@ _XIOError (
#ifdef NX_TRANS_EXIT
NXTransExit(1);
#else
+ exit_handler(dpy, exit_handler_data);
exit(1);
#endif
}
@@ -3749,6 +3816,7 @@ _XIOError (
/* shut up the compiler by returning something */
return 0;
#else
+ exit_handler(dpy, exit_handler_data);
exit (1);
#endif
/*NOTREACHED*/
@@ -3932,9 +4000,9 @@ int _XGetHostname (
return 0;
uname (&name);
- len = strlen (name.nodename);
+ len = (int) strlen (name.nodename);
if (len >= maxlen) len = maxlen - 1;
- strncpy (buf, name.nodename, len);
+ strncpy (buf, name.nodename, (size_t) len);
buf[len] = '\0';
#else
if (maxlen <= 0 || buf == NULL)
@@ -3943,7 +4011,7 @@ int _XGetHostname (
buf[0] = '\0';
(void) gethostname (buf, maxlen);
buf [maxlen - 1] = '\0';
- len = strlen(buf);
+ len = (int) strlen(buf);
#endif /* NEED_UTSNAME */
return len;
}
@@ -3972,6 +4040,7 @@ Screen *_XScreenOfWindow(Display *dpy, Window w)
return NULL;
}
+
/*
* WARNING: This implementation's pre-conditions and post-conditions
* must remain compatible with the old macro-based implementations of
diff --git a/nx-X11/lib/src/Xrm.c b/nx-X11/lib/src/Xrm.c
index c285e4221..5a68da3b1 100644
--- a/nx-X11/lib/src/Xrm.c
+++ b/nx-X11/lib/src/Xrm.c
@@ -81,7 +81,7 @@ information is kept on a per-level basis.
(3) Sometimes the widget instance tree is structured such that you get the same
class name repeated on the fully qualified widget name. This can result in the
-same database level occuring multiple times on the search list. The code below
+same database level occurring multiple times on the search list. The code below
only checks to see if you get two identical search lists in a row, rather than
look back through all database levels, but in practice this removes all
duplicates I've ever observed.
@@ -897,7 +897,7 @@ static void PutEntry(
/* bump to loose table, if any */
table = *(prev = &table->next);
if (!table || table->name != q ||
- (!quarks[2]) != table->leaf)
+ !quarks[2] != table->leaf)
break; /* not found */
}
}
@@ -1047,7 +1047,7 @@ XrmQPutStringResource(
if (!*pdb) *pdb = NewDatabase();
value.addr = (XPointer) str;
- value.size = strlen(str)+1;
+ value.size = (unsigned) strlen(str) + 1;
_XLockMutex(&(*pdb)->linfo);
PutEntry(*pdb, bindings, quarks, XrmQString, &value);
_XUnlockMutex(&(*pdb)->linfo);
@@ -1307,7 +1307,7 @@ static void GetDatabase(
char oldc;
/*
- * A parsing error has occured, toss everything on the line
+ * A parsing error has occurred, toss everything on the line
* a new_line can still be escaped with a '\'.
*/
@@ -1477,7 +1477,7 @@ static void GetDatabase(
/*
* It is important to make sure that there is room for at least
* four more characters in the buffer, since I can add that
- * many characters into the buffer after a backslash has occured.
+ * many characters into the buffer after a backslash has occurred.
*/
if (ptr + len > ptr_max) {
@@ -1532,7 +1532,7 @@ XrmPutStringResource(
if (!*pdb) *pdb = NewDatabase();
XrmStringToBindingQuarkList(specifier, bindings, quarks);
value.addr = (XPointer) str;
- value.size = strlen(str)+1;
+ value.size = (unsigned) strlen(str)+1;
_XLockMutex(&(*pdb)->linfo);
PutEntry(*pdb, bindings, quarks, XrmQString, &value);
_XUnlockMutex(&(*pdb)->linfo);
@@ -1637,11 +1637,11 @@ GetIncludeFile(
len = str - base + 1;
if (len + fnamelen >= BUFSIZ)
return;
- strncpy(realfname, base, len);
- strncpy(realfname + len, fname, fnamelen);
+ strncpy(realfname, base, (size_t) len);
+ strncpy(realfname + len, fname, (size_t) fnamelen);
realfname[len + fnamelen] = '\0';
} else {
- strncpy(realfname, fname, fnamelen);
+ strncpy(realfname, fname, (size_t) fnamelen);
realfname[fnamelen] = '\0';
}
if (!(str = ReadInFile(realfname)))
diff --git a/nx-X11/lib/src/globals.c b/nx-X11/lib/src/globals.c
index efae2f8bb..9ebb3fe3a 100644
--- a/nx-X11/lib/src/globals.c
+++ b/nx-X11/lib/src/globals.c
@@ -89,7 +89,7 @@ ZEROINIT (Display *, _XHeadOfDisplayList, NULL);
* Holds the two event type codes for this extension. The event type codes
* for this extension may vary depending on how many extensions are installed
* already, so the initial values given below will be added to the base event
- * code that is aquired when this extension is installed.
+ * code that is acquired when this extension is installed.
*
* These two variables must be available to programs that use this extension.
*/
diff --git a/nx-X11/lib/src/imConv.c b/nx-X11/lib/src/imConv.c
index c3c1974de..48bc79005 100644
--- a/nx-X11/lib/src/imConv.c
+++ b/nx-X11/lib/src/imConv.c
@@ -24,7 +24,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
- Auther: Kazunori Nishihara, Fuji Xerox Co.,Ltd.
+ Author: Kazunori Nishihara, Fuji Xerox Co.,Ltd.
kaz@ssdev.ksp.fujixerox.co.jp
Modifier: Takashi Fujiwara FUJITSU LIMITED
fujiwara@a80.tech.yk.fujitsu.co.jp
@@ -96,7 +96,7 @@ _XimGetLocaleCode (
/*
* Returns the locale dependent representation of a keysym.
- * The locale's encoding is passed in form of pointer to UCS convertor.
+ * The locale's encoding is passed in form of pointer to UCS converter.
* The resulting multi-byte sequence is placed starting at buf (a buffer
* with nbytes bytes, nbytes should be >= 8) and is NUL terminated.
* Returns the length of the resulting multi-byte sequence, excluding the
diff --git a/nx-X11/lib/src/locking.c b/nx-X11/lib/src/locking.c
index 9f4fe0677..ea5000e15 100644
--- a/nx-X11/lib/src/locking.c
+++ b/nx-X11/lib/src/locking.c
@@ -66,6 +66,8 @@ in this Software without prior written authorization from The Open Group.
/* in lcWrap.c */
extern LockInfoPtr _Xi18n_lock;
+/* in lcConv.c */
+extern LockInfoPtr _conv_lock;
#ifdef WIN32
static DWORD _X_TlsIndex = (DWORD)-1;
@@ -98,6 +100,7 @@ static xthread_t _Xthread_self(void)
static LockInfoRec global_lock;
static LockInfoRec i18n_lock;
+static LockInfoRec conv_lock;
static void _XLockMutex(
LockInfoPtr lip
@@ -130,6 +133,7 @@ static void _XFreeMutex(
{
xmutex_clear(lip->lock);
xmutex_free(lip->lock);
+ lip->lock = NULL;
}
#ifdef XTHREADS_WARN
@@ -453,6 +457,9 @@ static void _XLockDisplay(
XTHREADS_FILE_LINE_ARGS
)
{
+#ifdef XTHREADS
+ struct _XErrorThreadInfo *ti;
+#endif
#ifdef XTHREADS_WARN
_XLockDisplayWarn(dpy, file, line);
#else
@@ -460,6 +467,15 @@ static void _XLockDisplay(
#endif
if (dpy->lock->locking_level > 0)
_XDisplayLockWait(dpy);
+#ifdef XTHREADS
+ /*
+ * Skip the two function calls below which may generate requests
+ * when LockDisplay is called from within _XError.
+ */
+ for (ti = dpy->error_threads; ti; ti = ti->next)
+ if (ti->error_thread == xthread_self())
+ return;
+#endif
_XIDHandler(dpy);
_XSeqSyncFunction(dpy);
}
@@ -594,12 +610,22 @@ Status XInitThreads(void)
global_lock.lock = NULL;
return 0;
}
+ if (!(conv_lock.lock = xmutex_malloc())) {
+ xmutex_free(global_lock.lock);
+ global_lock.lock = NULL;
+ xmutex_free(i18n_lock.lock);
+ i18n_lock.lock = NULL;
+ return 0;
+ }
_Xglobal_lock = &global_lock;
xmutex_init(_Xglobal_lock->lock);
xmutex_set_name(_Xglobal_lock->lock, "Xlib global");
_Xi18n_lock = &i18n_lock;
xmutex_init(_Xi18n_lock->lock);
xmutex_set_name(_Xi18n_lock->lock, "Xlib i18n");
+ _conv_lock = &conv_lock;
+ xmutex_init(_conv_lock->lock);
+ xmutex_set_name(_conv_lock->lock, "Xlib conv");
_XLockMutex_fn = _XLockMutex;
_XUnlockMutex_fn = _XUnlockMutex;
_XCreateMutex_fn = _XCreateMutex;
diff --git a/nx-X11/lib/src/locking.h b/nx-X11/lib/src/locking.h
index 277c9afc8..4fb477978 100644
--- a/nx-X11/lib/src/locking.h
+++ b/nx-X11/lib/src/locking.h
@@ -149,6 +149,18 @@ typedef struct _LockInfoRec {
xmutex_t lock;
} LockInfoRec;
+/* A list of threads currently invoking error handlers on this display
+ * LockDisplay operates differently for these threads, avoiding
+ * generating any requests or reading any events as that can cause
+ * recursion into the error handling code, which will deadlock the
+ * thread.
+ */
+struct _XErrorThreadInfo
+{
+ struct _XErrorThreadInfo *next;
+ xthread_t error_thread;
+};
+
/* XOpenDis.c */
extern int (*_XInitDisplayLock_fn)(Display *dpy);
extern void (*_XFreeDisplayLock_fn)(Display *dpy);
diff --git a/nx-X11/lib/src/reallocarray.c b/nx-X11/lib/src/reallocarray.c
new file mode 100644
index 000000000..2c301bc86
--- /dev/null
+++ b/nx-X11/lib/src/reallocarray.c
@@ -0,0 +1,43 @@
+/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include "reallocarray.h"
+
+/*
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
+ */
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
+
+void *
+xreallocarray(void *optr, size_t nmemb, size_t size)
+{
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(optr, size * nmemb);
+}
diff --git a/nx-X11/lib/src/reallocarray.h b/nx-X11/lib/src/reallocarray.h
new file mode 100644
index 000000000..ee38ebf8d
--- /dev/null
+++ b/nx-X11/lib/src/reallocarray.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <X11/Xfuncproto.h>
+
+#ifndef HAVE_REALLOCARRAY
+extern _X_HIDDEN void *xreallocarray(void *optr, size_t nmemb, size_t size);
+# define reallocarray(ptr, n, size) xreallocarray((ptr), (size_t)(n), (size_t)(size))
+#endif
+
+#if defined(MALLOC_0_RETURNS_NULL) || defined(__clang_analyzer__)
+# define Xreallocarray(ptr, n, size) \
+ reallocarray((ptr), ((n) == 0 ? 1 : (n)), size)
+#else
+# define Xreallocarray(ptr, n, size) reallocarray((ptr), (n), (size))
+#endif
+
+#define Xmallocarray(n, size) Xreallocarray(NULL, (n), (size))
diff --git a/nx-X11/lib/src/util/makekeys.c b/nx-X11/lib/src/util/makekeys.c
index 897b882dc..4896cc539 100644
--- a/nx-X11/lib/src/util/makekeys.c
+++ b/nx-X11/lib/src/util/makekeys.c
@@ -28,17 +28,24 @@ from The Open Group.
/* Constructs hash tables for XStringToKeysym and XKeysymToString. */
-#include <nx-X11/X.h>
-#include <nx-X11/Xos.h>
-#include <nx-X11/Xresource.h>
-#include <nx-X11/keysymdef.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
-#include "../Xresinternal.h"
+typedef uint32_t Signature;
#define KTNUM 4000
+#define XK_VoidSymbol 0xffffff /* Void symbol */
+
+typedef unsigned long KeySym;
+
static struct info {
char *name;
KeySym val;
@@ -61,22 +68,34 @@ parse_line(const char *buf, char *key, KeySym *val, char *prefix)
char *tmp, *tmpa;
/* See if we can catch a straight XK_foo 0x1234-style definition first;
- * the trickery around tmp is to account for prefices. */
+ * the trickery around tmp is to account for prefixes. */
i = sscanf(buf, "#define %127s 0x%lx", key, val);
if (i == 2 && (tmp = strstr(key, "XK_"))) {
- memcpy(prefix, key, tmp - key);
+ memcpy(prefix, key, (size_t)(tmp - key));
prefix[tmp - key] = '\0';
tmp += 3;
memmove(key, tmp, strlen(tmp) + 1);
return 1;
}
+ /* See if we can parse one of the _EVDEVK symbols */
+ i = sscanf(buf, "#define %127s _EVDEVK(0x%lx)", key, val);
+ if (i == 2 && (tmp = strstr(key, "XK_"))) {
+ memcpy(prefix, key, (size_t)(tmp - key));
+ prefix[tmp - key] = '\0';
+ tmp += 3;
+ memmove(key, tmp, strlen(tmp) + 1);
+
+ *val += 0x10081000;
+ return 1;
+ }
+
/* Now try to catch alias (XK_foo XK_bar) definitions, and resolve them
* immediately: if the target is in the form XF86XK_foo, we need to
* canonicalise this to XF86foo before we do the lookup. */
i = sscanf(buf, "#define %127s %127s", key, alias);
if (i == 2 && (tmp = strstr(key, "XK_")) && (tmpa = strstr(alias, "XK_"))) {
- memcpy(prefix, key, tmp - key);
+ memcpy(prefix, key, (size_t)(tmp - key));
prefix[tmp - key] = '\0';
tmp += 3;
memmove(key, tmp, strlen(tmp) + 1);
diff --git a/nx-X11/lib/src/util/mkks.sh b/nx-X11/lib/src/util/mkks.sh
index 7af0e51ab..90f604922 100644
--- a/nx-X11/lib/src/util/mkks.sh
+++ b/nx-X11/lib/src/util/mkks.sh
@@ -1,10 +1,11 @@
#!/bin/sh
-awk 'BEGIN { \
+cat "$@" | awk 'BEGIN { \
printf "/*\n * This file is generated from %s. Do not edit.\n */\n", \
"$(INCLUDESRC)/keysymdef.h";\
} \
/^#define/ { \
len = length($2)-3; \
printf("{ \"%s\", %s },\n", substr($2,4,len), $3); \
-}' "$@"
+}'
+
diff --git a/nx-X11/lib/src/xcms/CvCols.c b/nx-X11/lib/src/xcms/CvCols.c
index 87d49311c..00bf8b242 100644
--- a/nx-X11/lib/src/xcms/CvCols.c
+++ b/nx-X11/lib/src/xcms/CvCols.c
@@ -39,6 +39,7 @@
#include "Xlibint.h"
#include "Xcmsint.h"
#include "Cv.h"
+#include "reallocarray.h"
/*
* LOCAL DEFINES
@@ -796,7 +797,9 @@ XcmsConvertColors(
* Make copy of array of color specifications
*/
if (nColors > 1) {
- pColors_tmp = Xmalloc(nColors * sizeof(XcmsColor));
+ pColors_tmp = Xmallocarray(nColors, sizeof(XcmsColor));
+ if (pColors_tmp == NULL)
+ return(XcmsFailure);
} else {
pColors_tmp = &Color1;
}
diff --git a/nx-X11/lib/src/xcms/HVCGcVC.c b/nx-X11/lib/src/xcms/HVCGcVC.c
index 7ace5f13f..e9eb3a1e9 100644
--- a/nx-X11/lib/src/xcms/HVCGcVC.c
+++ b/nx-X11/lib/src/xcms/HVCGcVC.c
@@ -170,7 +170,7 @@ XcmsTekHVCClipVC (
}
if (pColor->spec.TekHVC.V < hvc_max.spec.TekHVC.V) {
- /* return the intersection of the perpindicular line through */
+ /* return the intersection of the perpendicular line through */
/* the value and chroma given and the line from 0,0 and hvc_max. */
Chroma = pColor->spec.TekHVC.C;
Value = pColor->spec.TekHVC.V;
diff --git a/nx-X11/lib/src/xcms/HVCMxC.c b/nx-X11/lib/src/xcms/HVCMxC.c
index 074844ccc..3eb0929d9 100644
--- a/nx-X11/lib/src/xcms/HVCMxC.c
+++ b/nx-X11/lib/src/xcms/HVCMxC.c
@@ -39,7 +39,7 @@
* TekHVCMxC.c
*
* DESCRIPTION
- * Source for the XcmsTekHVCQueryMaxC() gamut boudary
+ * Source for the XcmsTekHVCQueryMaxC() gamut boundary
* querying routine.
*
*/
diff --git a/nx-X11/lib/src/xcms/LRGB.c b/nx-X11/lib/src/xcms/LRGB.c
index 4bfa3cfb1..ae42adda9 100644
--- a/nx-X11/lib/src/xcms/LRGB.c
+++ b/nx-X11/lib/src/xcms/LRGB.c
@@ -795,7 +795,7 @@ LINEAR_RGB_InitSCCData(
return(XcmsSuccess);
-FreeBlueTblElements:
+FreeBlueTblElements: _X_UNUSED
Xfree(pScreenData->pBlueTbl->pBase);
FreeBlueTbl:
@@ -1178,7 +1178,7 @@ _XcmsTableSearch(
/*
* DESCRIPTION
- * A binary search through the specificied table.
+ * A binary search through the specified table.
*
* RETURNS
* Returns 0 if failed; otherwise non-zero.
@@ -1293,7 +1293,7 @@ XcmsLRGB_RGB_ParseString(
* Attempt to parse the value portion.
*/
spec++;
- n = strlen(spec);
+ n = (int)strlen(spec);
if (n != 3 && n != 6 && n != 9 && n != 12) {
return(XcmsFailure);
}
@@ -1337,7 +1337,7 @@ XcmsLRGB_RGB_ParseString(
/*
* Check for proper prefix.
*/
- if (strncmp(spec, _XcmsRGB_prefix, n) != 0) {
+ if (strncmp(spec, _XcmsRGB_prefix, (size_t)n) != 0) {
return(XcmsFailure);
}
diff --git a/nx-X11/lib/src/xcms/Lab.c b/nx-X11/lib/src/xcms/Lab.c
index 6f7075643..52daa4e7b 100644
--- a/nx-X11/lib/src/xcms/Lab.c
+++ b/nx-X11/lib/src/xcms/Lab.c
@@ -149,7 +149,7 @@ CIELab_ParseString(
/*
* Check for proper prefix.
*/
- if (strncmp(spec, _XcmsCIELab_prefix, n) != 0) {
+ if (strncmp(spec, _XcmsCIELab_prefix, (size_t)n) != 0) {
return(XcmsFailure);
}
diff --git a/nx-X11/lib/src/xcms/Luv.c b/nx-X11/lib/src/xcms/Luv.c
index 2bce977ea..91d13a054 100644
--- a/nx-X11/lib/src/xcms/Luv.c
+++ b/nx-X11/lib/src/xcms/Luv.c
@@ -152,7 +152,7 @@ CIELuv_ParseString(
/*
* Check for proper prefix.
*/
- if (strncmp(spec, _XcmsCIELuv_prefix, n) != 0) {
+ if (strncmp(spec, _XcmsCIELuv_prefix, (size_t)n) != 0) {
return(XcmsFailure);
}
diff --git a/nx-X11/lib/src/xcms/StCols.c b/nx-X11/lib/src/xcms/StCols.c
index 42a29cd7f..22d6a10bc 100644
--- a/nx-X11/lib/src/xcms/StCols.c
+++ b/nx-X11/lib/src/xcms/StCols.c
@@ -38,6 +38,7 @@
#include "Xlibint.h"
#include "Xcmsint.h"
#include "Cv.h"
+#include "reallocarray.h"
/************************************************************************
@@ -85,7 +86,9 @@ XcmsStoreColors(
* overwrite the contents.
*/
if (nColors > 1) {
- pColors_tmp = Xmalloc(nColors * sizeof(XcmsColor));
+ pColors_tmp = Xmallocarray(nColors, sizeof(XcmsColor));
+ if (pColors_tmp == NULL)
+ return(XcmsFailure);
} else {
pColors_tmp = &Color1;
}
diff --git a/nx-X11/lib/src/xcms/cmsAllNCol.c b/nx-X11/lib/src/xcms/cmsAllNCol.c
index d39de6cbd..ae6827f4c 100644
--- a/nx-X11/lib/src/xcms/cmsAllNCol.c
+++ b/nx-X11/lib/src/xcms/cmsAllNCol.c
@@ -152,7 +152,7 @@ PassToServer:
GetReq(AllocNamedColor, req);
req->cmap = cmap;
- nbytes = req->nbytes = strlen(colorname);
+ nbytes = req->nbytes = (CARD16) strlen(colorname);
req->length += (nbytes + 3) >> 2; /* round up to mult of 4 */
_XSend(dpy, colorname, nbytes);
diff --git a/nx-X11/lib/src/xcms/cmsColNm.c b/nx-X11/lib/src/xcms/cmsColNm.c
index 829749112..e9ca5447b 100644
--- a/nx-X11/lib/src/xcms/cmsColNm.c
+++ b/nx-X11/lib/src/xcms/cmsColNm.c
@@ -210,6 +210,8 @@ _XcmsParseColorString(
*/
if ((len = strlen(color_string)) >= sizeof(string_buf)) {
string_lowered = Xmalloc(len+1);
+ if (string_lowered == NULL)
+ return(XcmsFailure);
} else {
string_lowered = string_buf;
}
@@ -417,8 +419,10 @@ _XcmsLookupColorName(
tmpName = *name;
Retry:
- if ((len = strlen(tmpName)) > 63) {
+ if ((len = (int)strlen(tmpName)) > 63) {
name_lowered = Xmalloc(len+1);
+ if (name_lowered == NULL)
+ return(XcmsFailure);
} else {
name_lowered = name_lowered_64;
}
@@ -505,7 +509,7 @@ RemoveSpaces(
/* REMOVE SPACES */
cptr = pString;
- for (i = strlen(pString); i; i--, cptr++) {
+ for (i = (int)strlen(pString); i; i--, cptr++) {
if (!isspace(*cptr)) {
*pString++ = *cptr;
count++;
@@ -731,7 +735,7 @@ LoadColornameDB(void)
pathname = XCMSDB;
}
- length = strlen(pathname);
+ length = (int)strlen(pathname);
if ((length == 0) || (length >= (BUFSIZ - 5))){
XcmsColorDbState = XcmsDbInitFailure;
return(XcmsFailure);
@@ -759,6 +763,13 @@ LoadColornameDB(void)
strings = Xmalloc(size);
pairs = Xcalloc(nEntries, sizeof(XcmsPair));
+ if (strings == NULL || pairs == NULL) {
+ free(strings);
+ free(pairs);
+ (void) fclose(stream);
+ XcmsColorDbState = XcmsDbInitFailure;
+ return(XcmsFailure);
+ }
ReadColornameDB(stream, pairs, strings);
(void) fclose(stream);
diff --git a/nx-X11/lib/src/xcms/cmsInt.c b/nx-X11/lib/src/xcms/cmsInt.c
index f4aef04ff..059b7d583 100644
--- a/nx-X11/lib/src/xcms/cmsInt.c
+++ b/nx-X11/lib/src/xcms/cmsInt.c
@@ -41,6 +41,7 @@
#include "Xlibint.h"
#include "Xcmsint.h"
#include "Cv.h"
+#include "reallocarray.h"
#ifndef XCMSCOMPPROC
# define XCMSCOMPPROC XcmsTekHVCClipC
@@ -82,7 +83,7 @@ _XcmsCopyPointerArray(
for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++);
n++; /* add 1 to include the NULL pointer */
- if ((newArray = Xmalloc(n * sizeof(XPointer)))) {
+ if ((newArray = Xmallocarray(n, sizeof(XPointer)))) {
memcpy((char *)newArray, (char *)pap,
(unsigned)(n * sizeof(XPointer)));
}
@@ -141,7 +142,7 @@ _XcmsPushPointerArray(
/* add 2: 1 for the new pointer and another for the NULL pointer */
n += 2;
- if ((newArray = Xmalloc(n * sizeof(XPointer)))) {
+ if ((newArray = Xmallocarray(n, sizeof(XPointer)))) {
memcpy((char *)(newArray+1),(char *)pap,
(unsigned)((n-1) * sizeof(XPointer)));
*newArray = p;
@@ -224,7 +225,7 @@ _XcmsFreeDefaultCCCs(
/*
* DESCRIPTION
* This routine frees the default XcmsCCC's associated with
- * each screen and its associated substructures as neccessary.
+ * each screen and its associated substructures as necessary.
*
* RETURNS
* void
@@ -296,7 +297,7 @@ _XcmsInitScrnInfo(
/*
* Check if the XcmsCCC's for each screen has been created.
- * Really dont need to be created until some routine uses the Xcms
+ * Really don't need to be created until some routine uses the Xcms
* API routines.
*/
if ((XcmsCCC)dpy->cms.defaultCCCs == NULL) {
diff --git a/nx-X11/lib/src/xcms/cmsLkCol.c b/nx-X11/lib/src/xcms/cmsLkCol.c
index a81c4cbf0..e93a9738b 100644
--- a/nx-X11/lib/src/xcms/cmsLkCol.c
+++ b/nx-X11/lib/src/xcms/cmsLkCol.c
@@ -150,7 +150,7 @@ PassToServer:
LockDisplay(dpy);
GetReq (LookupColor, req);
req->cmap = cmap;
- req->nbytes = n = strlen(colorname);
+ req->nbytes = (CARD16)(n = (int)strlen(colorname));
req->length += (n + 3) >> 2;
Data (dpy, colorname, (long)n);
if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
diff --git a/nx-X11/lib/src/xcms/xyY.c b/nx-X11/lib/src/xcms/xyY.c
index e85b8d249..a99d03849 100644
--- a/nx-X11/lib/src/xcms/xyY.c
+++ b/nx-X11/lib/src/xcms/xyY.c
@@ -145,7 +145,7 @@ CIExyY_ParseString(
/*
* Check for proper prefix.
*/
- if (strncmp(spec, _XcmsCIExyY_prefix, n) != 0) {
+ if (strncmp(spec, _XcmsCIExyY_prefix, (size_t)n) != 0) {
return(XcmsFailure);
}
diff --git a/nx-X11/lib/src/xkb/XKB.c b/nx-X11/lib/src/xkb/XKB.c
index 6df9c3ebc..f5317afdb 100644
--- a/nx-X11/lib/src/xkb/XKB.c
+++ b/nx-X11/lib/src/xkb/XKB.c
@@ -406,7 +406,7 @@ XkbSetDebuggingFlags(Display *dpy,
if (msg) {
char *out;
- req->msgLength = (unsigned short) strlen(msg) + 1;
+ req->msgLength = (CARD16) (strlen(msg) + 1);
req->length += (req->msgLength + (unsigned) 3) >> 2;
BufAlloc(char *, out, ((req->msgLength + (unsigned) 3) / 4) * 4);
memcpy(out, msg, req->msgLength);
diff --git a/nx-X11/lib/src/xkb/XKBAlloc.c b/nx-X11/lib/src/xkb/XKBAlloc.c
index 5621f713a..ff6aabd4f 100644
--- a/nx-X11/lib/src/xkb/XKBAlloc.c
+++ b/nx-X11/lib/src/xkb/XKBAlloc.c
@@ -44,7 +44,6 @@ Status
XkbAllocCompatMap(XkbDescPtr xkb, unsigned which, unsigned nSI)
{
XkbCompatMapPtr compat;
- XkbSymInterpretRec *prev_interpret;
if (!xkb)
return BadMatch;
@@ -55,18 +54,12 @@ XkbAllocCompatMap(XkbDescPtr xkb, unsigned which, unsigned nSI)
compat->size_si = nSI;
if (compat->sym_interpret == NULL)
compat->num_si = 0;
- prev_interpret = compat->sym_interpret;
- compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret,
- nSI, XkbSymInterpretRec);
+ _XkbResizeArray(compat->sym_interpret, compat->num_si,
+ nSI, XkbSymInterpretRec);
if (compat->sym_interpret == NULL) {
- _XkbFree(prev_interpret);
compat->size_si = compat->num_si = 0;
return BadAlloc;
}
- if (compat->num_si != 0) {
- _XkbClearElems(compat->sym_interpret, compat->num_si,
- compat->size_si - 1, XkbSymInterpretRec);
- }
return Success;
}
compat = _XkbTypedCalloc(1, XkbCompatMapRec);
@@ -150,22 +143,10 @@ XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases)
return BadAlloc;
}
if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
- if (names->key_aliases == NULL) {
- names->key_aliases = _XkbTypedCalloc(nTotalAliases, XkbKeyAliasRec);
- }
- else if (nTotalAliases > names->num_key_aliases) {
- XkbKeyAliasRec *prev_aliases = names->key_aliases;
-
- names->key_aliases = _XkbTypedRealloc(names->key_aliases,
- nTotalAliases,
- XkbKeyAliasRec);
- if (names->key_aliases != NULL) {
- _XkbClearElems(names->key_aliases, names->num_key_aliases,
- nTotalAliases - 1, XkbKeyAliasRec);
- }
- else {
- _XkbFree(prev_aliases);
- }
+ if ((names->key_aliases == NULL) ||
+ (nTotalAliases > names->num_key_aliases)) {
+ _XkbResizeArray(names->key_aliases, names->num_key_aliases,
+ nTotalAliases, XkbKeyAliasRec);
}
if (names->key_aliases == NULL) {
names->num_key_aliases = 0;
@@ -174,24 +155,13 @@ XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases)
names->num_key_aliases = nTotalAliases;
}
if ((which & XkbRGNamesMask) && (nTotalRG > 0)) {
- if (names->radio_groups == NULL) {
- names->radio_groups = _XkbTypedCalloc(nTotalRG, Atom);
+ if ((names->radio_groups == NULL) || (nTotalRG > names->num_rg)) {
+ _XkbResizeArray(names->radio_groups, names->num_rg, nTotalRG, Atom);
}
- else if (nTotalRG > names->num_rg) {
- Atom *prev_radio_groups = names->radio_groups;
-
- names->radio_groups =
- _XkbTypedRealloc(names->radio_groups, nTotalRG, Atom);
- if (names->radio_groups != NULL) {
- _XkbClearElems(names->radio_groups, names->num_rg, nTotalRG - 1,
- Atom);
- }
- else {
- _XkbFree(prev_radio_groups);
- }
- }
- if (names->radio_groups == NULL)
+ if (names->radio_groups == NULL) {
+ names->num_rg = 0;
return BadAlloc;
+ }
names->num_rg = nTotalRG;
}
return Success;
@@ -350,16 +320,13 @@ XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi, unsigned ledClass, unsigned ledId)
return devli;
}
if (devi->num_leds >= devi->sz_leds) {
- XkbDeviceLedInfoRec *prev_leds = devi->leds;
-
if (devi->sz_leds > 0)
devi->sz_leds *= 2;
else
devi->sz_leds = 1;
- devi->leds = _XkbTypedRealloc(devi->leds, devi->sz_leds,
- XkbDeviceLedInfoRec);
+ _XkbResizeArray(devi->leds, devi->num_leds, devi->sz_leds,
+ XkbDeviceLedInfoRec);
if (!devi->leds) {
- _XkbFree(prev_leds);
devi->sz_leds = devi->num_leds = 0;
return NULL;
}
@@ -380,8 +347,6 @@ XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi, unsigned ledClass, unsigned ledId)
Status
XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi, unsigned newTotal)
{
- XkbAction *prev_btn_acts;
-
if ((!devi) || (newTotal > 255))
return BadValue;
if ((devi->btn_acts != NULL) && (newTotal == devi->num_btns))
@@ -394,10 +359,8 @@ XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi, unsigned newTotal)
devi->num_btns = 0;
return Success;
}
- prev_btn_acts = devi->btn_acts;
- devi->btn_acts = _XkbTypedRealloc(devi->btn_acts, newTotal, XkbAction);
+ _XkbResizeArray(devi->btn_acts, devi->num_btns, newTotal, XkbAction);
if (devi->btn_acts == NULL) {
- _XkbFree(prev_btn_acts);
devi->num_btns = 0;
return BadAlloc;
}
diff --git a/nx-X11/lib/src/xkb/XKBBind.c b/nx-X11/lib/src/xkb/XKBBind.c
index ffe5ad9d7..726f3b2cc 100644
--- a/nx-X11/lib/src/xkb/XKBBind.c
+++ b/nx-X11/lib/src/xkb/XKBBind.c
@@ -179,7 +179,7 @@ XKeysymToKeycode(Display *dpy, KeySym ks)
for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) {
if (j < (int) XkbKeyNumSyms(xkb, i)) {
gotOne = 1;
- if (XkbKeySym(xkb, i, j) == ks)
+ if ((XkbKeySym(xkb, i, j) == ks))
return i;
}
}
@@ -236,7 +236,21 @@ XLookupKeysym(register XKeyEvent * event, int col)
if (_XkbUnavailable(dpy))
return _XLookupKeysym(event, col);
_XkbCheckPendingRefresh(dpy, dpy->xkb_info);
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#elif defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
return XKeycodeToKeysym(dpy, event->keycode, col);
+#ifdef __clang__
+#pragma clang diagnostic pop
+#elif defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+
}
/*
@@ -601,8 +615,8 @@ _XkbReloadDpy(Display *dpy)
}
int
-XkbTranslateKeySym(register Display *dpy,
- register KeySym *sym_rtrn,
+XkbTranslateKeySym(Display *dpy,
+ KeySym *sym_rtrn,
unsigned int mods,
char *buffer,
int nbytes,
@@ -770,7 +784,7 @@ XkbLookupKeyBinding(Display *dpy,
*extra_rtrn = (tmp - nbytes);
tmp = nbytes;
}
- memcpy(buffer, p->string, tmp);
+ memcpy(buffer, p->string, (size_t) tmp);
if (tmp < nbytes)
buffer[tmp] = '\0';
return tmp;
diff --git a/nx-X11/lib/src/xkb/XKBExtDev.c b/nx-X11/lib/src/xkb/XKBExtDev.c
index cb40ecd04..671f308c9 100644
--- a/nx-X11/lib/src/xkb/XKBExtDev.c
+++ b/nx-X11/lib/src/xkb/XKBExtDev.c
@@ -651,7 +651,7 @@ _XkbWriteSetDeviceInfo(char *wire,
if (changes->changed & XkbXI_ButtonActionsMask) {
int size = changes->num_btns * SIZEOF(xkbActionWireDesc);
- memcpy(wire, (char *) &devi->btn_acts[changes->first_btn], size);
+ memcpy(wire, (char *) &devi->btn_acts[changes->first_btn], (size_t) size);
wire += size;
}
if (changes->changed & XkbXI_IndicatorsMask) {
diff --git a/nx-X11/lib/src/xkb/XKBGAlloc.c b/nx-X11/lib/src/xkb/XKBGAlloc.c
index ab05f8d88..724228ddf 100644
--- a/nx-X11/lib/src/xkb/XKBGAlloc.c
+++ b/nx-X11/lib/src/xkb/XKBGAlloc.c
@@ -69,8 +69,8 @@ _XkbFreeGeomLeafElems(Bool freeAll,
ptr = *elems;
extra = ((*num_inout) - (first + count)) * elem_sz;
if (extra > 0)
- memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz],
- extra);
+ memmove(&ptr[(unsigned) first * elem_sz], &ptr[(unsigned)(first + count) * elem_sz],
+ (size_t) extra);
(*num_inout) -= count;
}
return;
@@ -124,7 +124,7 @@ _XkbFreeGeomNonLeafElems(Bool freeAll,
else {
i = ((*num_inout) - (first + count)) * elem_sz;
ptr = *elems;
- memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz], i);
+ memmove(&ptr[(unsigned) first * elem_sz], &ptr[(unsigned)(first + count) * elem_sz], (size_t) i);
(*num_inout) -= count;
}
return;
diff --git a/nx-X11/lib/src/xkb/XKBGetByName.c b/nx-X11/lib/src/xkb/XKBGetByName.c
index c673781ed..99dcd7405 100644
--- a/nx-X11/lib/src/xkb/XKBGetByName.c
+++ b/nx-X11/lib/src/xkb/XKBGetByName.c
@@ -109,32 +109,32 @@ XkbGetKeyboardByName(Display *dpy,
*str++ = mapLen;
if (mapLen > 0) {
- memcpy(str, names->keymap, mapLen);
+ memcpy(str, names->keymap, (size_t) mapLen);
str += mapLen;
}
*str++ = codesLen;
if (codesLen > 0) {
- memcpy(str, names->keycodes, codesLen);
+ memcpy(str, names->keycodes, (size_t) codesLen);
str += codesLen;
}
*str++ = typesLen;
if (typesLen > 0) {
- memcpy(str, names->types, typesLen);
+ memcpy(str, names->types, (size_t) typesLen);
str += typesLen;
}
*str++ = compatLen;
if (compatLen > 0) {
- memcpy(str, names->compat, compatLen);
+ memcpy(str, names->compat, (size_t) compatLen);
str += compatLen;
}
*str++ = symsLen;
if (symsLen > 0) {
- memcpy(str, names->symbols, symsLen);
+ memcpy(str, names->symbols, (size_t) symsLen);
str += symsLen;
}
*str++ = geomLen;
if (geomLen > 0) {
- memcpy(str, names->geometry, geomLen);
+ memcpy(str, names->geometry, (size_t) geomLen);
str += geomLen;
}
if ((!_XReply(dpy, (xReply *) &rep, 0, xFalse)) || (!rep.reported))
diff --git a/nx-X11/lib/src/xkb/XKBGetMap.c b/nx-X11/lib/src/xkb/XKBGetMap.c
index 6e3c74343..2a28e1b27 100644
--- a/nx-X11/lib/src/xkb/XKBGetMap.c
+++ b/nx-X11/lib/src/xkb/XKBGetMap.c
@@ -63,12 +63,9 @@ _XkbReadKeyTypes(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep)
if (desc->nMapEntries > 0) {
if ((type->map == NULL) ||
(desc->nMapEntries > type->map_count)) {
- XkbKTMapEntryRec *prev_map = type->map;
-
- type->map = _XkbTypedRealloc(type->map, desc->nMapEntries,
- XkbKTMapEntryRec);
+ _XkbResizeArray(type->map, type->map_count,
+ desc->nMapEntries, XkbKTMapEntryRec);
if (type->map == NULL) {
- _XkbFree(prev_map);
return BadAlloc;
}
}
@@ -81,13 +78,9 @@ _XkbReadKeyTypes(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep)
if (desc->preserve && (desc->nMapEntries > 0)) {
if ((!type->preserve) || (desc->nMapEntries > lastMapCount)) {
- XkbModsRec *prev_preserve = type->preserve;
-
- type->preserve = _XkbTypedRealloc(type->preserve,
- desc->nMapEntries,
- XkbModsRec);
+ _XkbResizeArray(type->preserve, lastMapCount,
+ desc->nMapEntries, XkbModsRec);
if (type->preserve == NULL) {
- _XkbFree(prev_preserve);
return BadAlloc;
}
}
@@ -188,12 +181,10 @@ _XkbReadKeySyms(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep)
oldMap->offset = offset;
if (offset + newMap->nSyms >= map->size_syms) {
register int sz;
- KeySym *prev_syms = map->syms;
sz = map->size_syms + 128;
- map->syms = _XkbTypedRealloc(map->syms, sz, KeySym);
+ _XkbResizeArray(map->syms, map->size_syms, sz, KeySym);
if (map->syms == NULL) {
- _XkbFree(prev_syms);
map->size_syms = 0;
return BadAlloc;
}
@@ -261,7 +252,7 @@ _XkbReadKeyActions(XkbReadBufferPtr buf, XkbDescPtr info, xkbGetMapReply *rep)
if (nKeyActs < sizeof numDescBuf)
numDesc = numDescBuf;
else
- numDesc = Xmalloc(nKeyActs * sizeof(CARD8));
+ numDesc = Xmallocarray(nKeyActs, sizeof(CARD8));
if (!_XkbCopyFromReadBuffer(buf, (char *) numDesc, nKeyActs)) {
ret = BadLength;
diff --git a/nx-X11/lib/src/xkb/XKBList.c b/nx-X11/lib/src/xkb/XKBList.c
index d3d29e2a6..ea61250a0 100644
--- a/nx-X11/lib/src/xkb/XKBList.c
+++ b/nx-X11/lib/src/xkb/XKBList.c
@@ -82,7 +82,7 @@ _ReadListing(XkbReadBufferPtr buf, int count, Status * status_rtrn)
str = (char *) _XkbGetReadBufferPtr(buf, wlen);
if (!str)
goto BAILOUT;
- memcpy(this->name, str, slen);
+ memcpy(this->name, str, (size_t) slen);
}
return first;
BAILOUT:
@@ -154,32 +154,32 @@ XkbListComponents(Display *dpy,
*str++ = mapLen;
if (mapLen > 0) {
- memcpy(str, ptrns->keymap, mapLen);
+ memcpy(str, ptrns->keymap, (size_t) mapLen);
str += mapLen;
}
*str++ = codesLen;
if (codesLen > 0) {
- memcpy(str, ptrns->keycodes, codesLen);
+ memcpy(str, ptrns->keycodes, (size_t) codesLen);
str += codesLen;
}
*str++ = typesLen;
if (typesLen > 0) {
- memcpy(str, ptrns->types, typesLen);
+ memcpy(str, ptrns->types, (size_t) typesLen);
str += typesLen;
}
*str++ = compatLen;
if (compatLen > 0) {
- memcpy(str, ptrns->compat, compatLen);
+ memcpy(str, ptrns->compat, (size_t) compatLen);
str += compatLen;
}
*str++ = symsLen;
if (symsLen > 0) {
- memcpy(str, ptrns->symbols, symsLen);
+ memcpy(str, ptrns->symbols, (size_t) symsLen);
str += symsLen;
}
*str++ = geomLen;
if (geomLen > 0) {
- memcpy(str, ptrns->geometry, geomLen);
+ memcpy(str, ptrns->geometry, (size_t) geomLen);
str += geomLen;
}
if (!_XReply(dpy, (xReply *) &rep, 0, xFalse))
diff --git a/nx-X11/lib/src/xkb/XKBMAlloc.c b/nx-X11/lib/src/xkb/XKBMAlloc.c
index 2467a2024..fdfd54bab 100644
--- a/nx-X11/lib/src/xkb/XKBMAlloc.c
+++ b/nx-X11/lib/src/xkb/XKBMAlloc.c
@@ -69,25 +69,17 @@ XkbAllocClientMap(XkbDescPtr xkb, unsigned which, unsigned nTotalTypes)
if ((which & XkbKeyTypesMask) && (nTotalTypes > 0)) {
if (map->types == NULL) {
- map->types = _XkbTypedCalloc(nTotalTypes, XkbKeyTypeRec);
- if (map->types == NULL)
- return BadAlloc;
- map->num_types = 0;
- map->size_types = nTotalTypes;
+ map->num_types = map->size_types = 0;
}
- else if (map->size_types < nTotalTypes) {
- XkbKeyTypeRec *prev_types = map->types;
+ if ((map->types == NULL) || (map->size_types < nTotalTypes)) {
+ _XkbResizeArray(map->types, map->size_types, nTotalTypes,
+ XkbKeyTypeRec);
- map->types =
- _XkbTypedRealloc(map->types, nTotalTypes, XkbKeyTypeRec);
if (map->types == NULL) {
- _XkbFree(prev_types);
map->num_types = map->size_types = 0;
return BadAlloc;
}
map->size_types = nTotalTypes;
- bzero(&map->types[map->num_types],
- ((map->size_types - map->num_types) * sizeof(XkbKeyTypeRec)));
}
}
if (which & XkbKeySymsMask) {
@@ -164,26 +156,20 @@ XkbAllocServerMap(XkbDescPtr xkb, unsigned which, unsigned nNewActions)
if (nNewActions < 1)
nNewActions = 1;
if (map->acts == NULL) {
- map->acts = _XkbTypedCalloc((nNewActions + 1), XkbAction);
- if (map->acts == NULL)
- return BadAlloc;
map->num_acts = 1;
- map->size_acts = nNewActions + 1;
+ map->size_acts = 0;
}
- else if ((map->size_acts - map->num_acts) < nNewActions) {
+ if ((map->acts == NULL) ||
+ ((map->size_acts - map->num_acts) < nNewActions)) {
unsigned need;
- XkbAction *prev_acts = map->acts;
need = map->num_acts + nNewActions;
- map->acts = _XkbTypedRealloc(map->acts, need, XkbAction);
+ _XkbResizeArray(map->acts, map->size_acts, need, XkbAction);
if (map->acts == NULL) {
- _XkbFree(prev_acts);
map->num_acts = map->size_acts = 0;
return BadAlloc;
}
map->size_acts = need;
- bzero(&map->acts[map->num_acts],
- ((map->size_acts - map->num_acts) * sizeof(XkbAction)));
}
if (map->key_acts == NULL) {
i = xkb->max_key_code + 1;
@@ -390,24 +376,18 @@ XkbResizeKeyType(XkbDescPtr xkb,
type->map_count = 0;
}
else {
- XkbKTMapEntryRec *prev_map = type->map;
-
if ((map_count > type->map_count) || (type->map == NULL))
- type->map =
- _XkbTypedRealloc(type->map, map_count, XkbKTMapEntryRec);
+ _XkbResizeArray(type->map, type->map_count, map_count,
+ XkbKTMapEntryRec);
if (!type->map) {
- _XkbFree(prev_map);
return BadAlloc;
}
if (want_preserve) {
- XkbModsRec *prev_preserve = type->preserve;
-
if ((map_count > type->map_count) || (type->preserve == NULL)) {
- type->preserve = _XkbTypedRealloc(type->preserve, map_count,
- XkbModsRec);
+ _XkbResizeArray(type->preserve, type->map_count, map_count,
+ XkbModsRec);
}
if (!type->preserve) {
- _XkbFree(prev_preserve);
return BadAlloc;
}
}
@@ -419,12 +399,8 @@ XkbResizeKeyType(XkbDescPtr xkb,
}
if ((new_num_lvls > type->num_levels) || (type->level_names == NULL)) {
- Atom *prev_level_names = type->level_names;
-
- type->level_names =
- _XkbTypedRealloc(type->level_names, new_num_lvls, Atom);
+ _XkbResizeArray(type->level_names, type->num_levels, new_num_lvls, Atom);
if (!type->level_names) {
- _XkbFree(prev_level_names);
return BadAlloc;
}
}
@@ -705,7 +681,7 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
if (changes) {
changes->map.changed = _ExtendRange(changes->map.changed,
XkbVirtualModMapMask, minKC,
- &changes->map.first_modmap_key,
+ &changes->map.first_vmodmap_key,
&changes->map.num_vmodmap_keys);
}
}
@@ -728,21 +704,11 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
tmp = maxKC - xkb->max_key_code;
if (xkb->map) {
if (xkb->map->key_sym_map) {
- XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map;
-
- xkb->map->key_sym_map = _XkbTypedRealloc(xkb->map->key_sym_map,
- (maxKC + 1), XkbSymMapRec);
+ _XkbResizeArray(xkb->map->key_sym_map, xkb->max_key_code + 1,
+ (maxKC + 1), XkbSymMapRec);
if (!xkb->map->key_sym_map) {
- _XkbFree(prev_key_sym_map);
return BadAlloc;
}
-#ifdef NXAGENT_SERVER
- bzero((char *) &xkb->map->key_sym_map[xkb->max_key_code + 1],
- tmp * sizeof(XkbSymMapRec));
-#else
- bzero((char *) &xkb->map->key_sym_map[xkb->max_key_code],
- tmp * sizeof(XkbSymMapRec));
-#endif
if (changes) {
changes->map.changed = _ExtendRange(changes->map.changed,
XkbKeySymsMask, maxKC,
@@ -751,19 +717,11 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
}
}
if (xkb->map->modmap) {
- unsigned char *prev_modmap = xkb->map->modmap;
-
- xkb->map->modmap = _XkbTypedRealloc(xkb->map->modmap,
- (maxKC + 1), unsigned char);
+ _XkbResizeArray(xkb->map->modmap, xkb->max_key_code + 1,
+ (maxKC + 1), unsigned char);
if (!xkb->map->modmap) {
- _XkbFree(prev_modmap);
return BadAlloc;
}
-#ifdef NXAGENT_SERVER
- bzero((char *) &xkb->map->modmap[xkb->max_key_code + 1], tmp);
-#else
- bzero((char *) &xkb->map->modmap[xkb->max_key_code], tmp);
-#endif
if (changes) {
changes->map.changed = _ExtendRange(changes->map.changed,
XkbModifierMapMask, maxKC,
@@ -774,22 +732,11 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
}
if (xkb->server) {
if (xkb->server->behaviors) {
- XkbBehavior *prev_behaviors = xkb->server->behaviors;
-
- xkb->server->behaviors =
- _XkbTypedRealloc(xkb->server->behaviors, (maxKC + 1),
- XkbBehavior);
+ _XkbResizeArray(xkb->server->behaviors, xkb->max_key_code + 1,
+ (maxKC + 1), XkbBehavior);
if (!xkb->server->behaviors) {
- _XkbFree(prev_behaviors);
return BadAlloc;
}
-#ifdef NXAGENT_SERVER
- bzero((char *) &xkb->server->behaviors[xkb->max_key_code + 1],
- tmp * sizeof(XkbBehavior));
-#else
- bzero((char *) &xkb->server->behaviors[xkb->max_key_code],
- tmp * sizeof(XkbBehavior));
-#endif
if (changes) {
changes->map.changed = _ExtendRange(changes->map.changed,
XkbKeyBehaviorsMask, maxKC,
@@ -798,21 +745,11 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
}
}
if (xkb->server->key_acts) {
- unsigned short *prev_key_acts = xkb->server->key_acts;
-
- xkb->server->key_acts = _XkbTypedRealloc(xkb->server->key_acts,
- (maxKC + 1), unsigned short);
+ _XkbResizeArray(xkb->server->key_acts, xkb->max_key_code + 1,
+ (maxKC + 1), unsigned short);
if (!xkb->server->key_acts) {
- _XkbFree(prev_key_acts);
return BadAlloc;
}
-#ifdef NXAGENT_SERVER
- bzero((char *) &xkb->server->key_acts[xkb->max_key_code + 1],
- tmp * sizeof(unsigned short));
-#else
- bzero((char *) &xkb->server->key_acts[xkb->max_key_code],
- tmp * sizeof(unsigned short));
-#endif
if (changes) {
changes->map.changed = _ExtendRange(changes->map.changed,
XkbKeyActionsMask, maxKC,
@@ -821,45 +758,25 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
}
}
if (xkb->server->vmodmap) {
- unsigned short *prev_vmodmap = xkb->server->vmodmap;
-
- xkb->server->vmodmap = _XkbTypedRealloc(xkb->server->vmodmap,
- (maxKC + 1), unsigned short);
+ _XkbResizeArray(xkb->server->vmodmap, xkb->max_key_code + 1,
+ (maxKC + 1), unsigned short);
if (!xkb->server->vmodmap) {
- _XkbFree(prev_vmodmap);
return BadAlloc;
}
-#ifdef NXAGENT_SERVER
- bzero((char *) &xkb->server->vmodmap[xkb->max_key_code + 1],
- tmp * sizeof(unsigned short));
-#else
- bzero((char *) &xkb->server->vmodmap[xkb->max_key_code],
- tmp * sizeof(unsigned short));
-#endif
if (changes) {
changes->map.changed = _ExtendRange(changes->map.changed,
XkbVirtualModMapMask, maxKC,
- &changes->map.first_modmap_key,
+ &changes->map.first_vmodmap_key,
&changes->map.num_vmodmap_keys);
}
}
}
if ((xkb->names) && (xkb->names->keys)) {
- XkbKeyNameRec *prev_keys = xkb->names->keys;
-
- xkb->names->keys = _XkbTypedRealloc(xkb->names->keys,
- (maxKC + 1), XkbKeyNameRec);
+ _XkbResizeArray(xkb->names->keys, xkb->max_key_code + 1,
+ (maxKC + 1), XkbKeyNameRec);
if (!xkb->names->keys) {
- _XkbFree(prev_keys);
return BadAlloc;
}
-#ifdef NXAGENT_SERVER
- bzero((char *) &xkb->names->keys[xkb->max_key_code + 1],
- tmp * sizeof(XkbKeyNameRec));
-#else
- bzero((char *) &xkb->names->keys[xkb->max_key_code],
- tmp * sizeof(XkbKeyNameRec));
-#endif
if (changes) {
changes->names.changed = _ExtendRange(changes->names.changed,
XkbKeyNamesMask, maxKC,
diff --git a/nx-X11/lib/src/xkb/XKBMisc.c b/nx-X11/lib/src/xkb/XKBMisc.c
index ab48b6124..0baf6f061 100644
--- a/nx-X11/lib/src/xkb/XKBMisc.c
+++ b/nx-X11/lib/src/xkb/XKBMisc.c
@@ -735,7 +735,7 @@ XkbChangeTypesOfKey(XkbDescPtr xkb,
return BadAlloc;
}
pSyms = XkbKeySymsPtr(xkb, key);
- memcpy(oldSyms, pSyms, XkbKeyNumSyms(xkb, key) * sizeof(KeySym));
+ memcpy(oldSyms, pSyms, (size_t) XkbKeyNumSyms(xkb, key) * sizeof(KeySym));
pSyms = XkbResizeKeySyms(xkb, key, width * nGroups);
if (pSyms == NULL)
return BadAlloc;
@@ -754,7 +754,7 @@ XkbChangeTypesOfKey(XkbDescPtr xkb,
XkbAction oldActs[XkbMaxSymsPerKey], *pActs;
pActs = XkbKeyActionsPtr(xkb, key);
- memcpy(oldActs, pActs, XkbKeyNumSyms(xkb, key) * sizeof(XkbAction));
+ memcpy(oldActs, pActs, (size_t) XkbKeyNumSyms(xkb, key) * sizeof(XkbAction));
pActs = XkbResizeKeyActions(xkb, key, width * nGroups);
if (pActs == NULL)
return BadAlloc;
@@ -857,7 +857,7 @@ XkbUpdateKeyTypeVirtualMods(XkbDescPtr xkb,
XkbChangesPtr changes)
{
register unsigned int i;
- unsigned int mask = 0;
+ unsigned int mask;
XkbVirtualModsToReal(xkb, type->mods.vmods, &mask);
type->mods.mask = type->mods.real_mods | mask;
@@ -919,7 +919,7 @@ XkbApplyVirtualModChanges(XkbDescPtr xkb,
changes);
}
if (changed & xkb->ctrls->internal.vmods) {
- unsigned int newMask = 0;
+ unsigned int newMask;
XkbVirtualModsToReal(xkb, xkb->ctrls->internal.vmods, &newMask);
newMask |= xkb->ctrls->internal.real_mods;
@@ -932,7 +932,7 @@ XkbApplyVirtualModChanges(XkbDescPtr xkb,
}
}
if (changed & xkb->ctrls->ignore_lock.vmods) {
- unsigned int newMask = 0;
+ unsigned int newMask;
XkbVirtualModsToReal(xkb, xkb->ctrls->ignore_lock.vmods, &newMask);
newMask |= xkb->ctrls->ignore_lock.real_mods;
@@ -950,7 +950,7 @@ XkbApplyVirtualModChanges(XkbDescPtr xkb,
map = &xkb->indicators->maps[0];
for (i = 0; i < XkbNumIndicators; i++, map++) {
if (map->mods.vmods & changed) {
- unsigned int newMask = 0;
+ unsigned int newMask;
XkbVirtualModsToReal(xkb, map->mods.vmods, &newMask);
newMask |= map->mods.real_mods;
@@ -969,7 +969,7 @@ XkbApplyVirtualModChanges(XkbDescPtr xkb,
compat = xkb->compat;
for (i = 0; i < XkbNumKbdGroups; i++) {
- unsigned int newMask = 0;
+ unsigned int newMask;
XkbVirtualModsToReal(xkb, compat->groups[i].vmods, &newMask);
newMask |= compat->groups[i].real_mods;
diff --git a/nx-X11/lib/src/xkb/XKBNames.c b/nx-X11/lib/src/xkb/XKBNames.c
index 951fd1da8..c14329203 100644
--- a/nx-X11/lib/src/xkb/XKBNames.c
+++ b/nx-X11/lib/src/xkb/XKBNames.c
@@ -205,14 +205,14 @@ _XkbReadGetNamesReply(Display *dpy,
if (rep->nRadioGroups > 0) {
Atom *rgNames;
- if (names->radio_groups == NULL)
- names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups, Atom);
- else if (names->num_rg < rep->nRadioGroups) {
- names->radio_groups = _XkbTypedRealloc(names->radio_groups,
- rep->nRadioGroups, Atom);
+ if ((names->radio_groups == NULL) ||
+ (names->num_rg < rep->nRadioGroups)) {
+ _XkbResizeArray(names->radio_groups, names->num_rg,
+ rep->nRadioGroups, Atom);
}
rgNames = names->radio_groups;
if (!rgNames) {
+ names->num_rg = 0;
goto BAILOUT;
}
if (!_XkbReadBufferCopy32
diff --git a/nx-X11/lib/src/xkb/XKBRdBuf.c b/nx-X11/lib/src/xkb/XKBRdBuf.c
index 381f4c900..a34039f37 100644
--- a/nx-X11/lib/src/xkb/XKBRdBuf.c
+++ b/nx-X11/lib/src/xkb/XKBRdBuf.c
@@ -71,7 +71,7 @@ _XkbCopyFromReadBuffer(XkbReadBufferPtr from, char *to, int size)
if ((from == NULL) || (from->error) || (to == NULL) || (size < 1) ||
(_XkbReadBufferDataLeft(from) < size))
return 0;
- memcpy(to, from->data, size);
+ memcpy(to, from->data, (size_t)size);
from->data += size;
return 1;
}
diff --git a/nx-X11/lib/src/xkb/XKBSetGeom.c b/nx-X11/lib/src/xkb/XKBSetGeom.c
index ee254e0dc..5d94072ce 100644
--- a/nx-X11/lib/src/xkb/XKBSetGeom.c
+++ b/nx-X11/lib/src/xkb/XKBSetGeom.c
@@ -52,7 +52,7 @@ _WriteCountedString(char *wire, char *str)
{
CARD16 len, *pLen;
- len = (str ? strlen(str) : 0);
+ len = (CARD16) (str ? strlen(str) : 0);
pLen = (CARD16 *) wire;
*pLen = len;
if (len && str)
@@ -69,8 +69,8 @@ _SizeGeomProperties(XkbGeometryPtr geom)
for (size = i = 0, prop = geom->properties; i < geom->num_properties;
i++, prop++) {
- size += _SizeCountedString(prop->name);
- size += _SizeCountedString(prop->value);
+ size = (int) ((unsigned) size + _SizeCountedString(prop->name));
+ size = (int) ((unsigned) size + _SizeCountedString(prop->value));
}
return size;
}
@@ -82,7 +82,7 @@ _SizeGeomColors(XkbGeometryPtr geom)
register XkbColorPtr color;
for (i = size = 0, color = geom->colors; i < geom->num_colors; i++, color++) {
- size += _SizeCountedString(color->spec);
+ size = (int) ((unsigned) size + _SizeCountedString(color->spec));
}
return size;
}
@@ -114,11 +114,11 @@ _SizeGeomDoodads(int num_doodads, XkbDoodadPtr doodad)
for (i = size = 0; i < num_doodads; i++, doodad++) {
size += SIZEOF(xkbAnyDoodadWireDesc);
if (doodad->any.type == XkbTextDoodad) {
- size += _SizeCountedString(doodad->text.text);
- size += _SizeCountedString(doodad->text.font);
+ size = (int) ((unsigned) size + _SizeCountedString(doodad->text.text));
+ size = (int) ((unsigned) size + _SizeCountedString(doodad->text.font));
}
else if (doodad->any.type == XkbLogoDoodad) {
- size += _SizeCountedString(doodad->logo.logo_name);
+ size = (int) ((unsigned) size + _SizeCountedString(doodad->logo.logo_name));
}
}
return size;
@@ -389,7 +389,7 @@ _WriteGeomKeyAliases(char *wire, XkbGeometryPtr geom)
sz = geom->num_key_aliases * (XkbKeyNameLength * 2);
if (sz > 0) {
- memcpy(wire, (char *) geom->key_aliases, sz);
+ memcpy(wire, (char *) geom->key_aliases, (size_t)sz);
wire += sz;
}
return wire;
@@ -404,7 +404,7 @@ _SendSetGeometry(Display *dpy, XkbGeometryPtr geom, xkbSetGeometryReq *req)
char *wire, *tbuf;
sz = 0;
- sz += _SizeCountedString(geom->label_font);
+ sz = (int) ((unsigned) (sz + _SizeCountedString(geom->label_font)));
sz += _SizeGeomProperties(geom);
sz += _SizeGeomColors(geom);
sz += _SizeGeomShapes(geom);
diff --git a/nx-X11/lib/src/xkb/XKBlibint.h b/nx-X11/lib/src/xkb/XKBlibint.h
index dad48b703..0b9a096b4 100644
--- a/nx-X11/lib/src/xkb/XKBlibint.h
+++ b/nx-X11/lib/src/xkb/XKBlibint.h
@@ -29,6 +29,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <nx-X11/Xutil.h>
#include <nx-X11/XKBlib.h>
+#include "reallocarray.h"
#define XkbMapPending (1<<0)
#define XkbXlibNewKeyboard (1<<1)
@@ -119,11 +120,26 @@ typedef struct _XkbReadBuffer {
#define _XkbRealloc(o,s) Xrealloc((o),(s))
#define _XkbTypedAlloc(t) ((t *)Xmalloc(sizeof(t)))
#define _XkbTypedCalloc(n,t) ((t *)Xcalloc((n),sizeof(t)))
-#define _XkbTypedRealloc(o,n,t) \
- ((o) ? (t *)Xrealloc((o), (n)*sizeof(t)) : _XkbTypedCalloc(n,t))
-#define _XkbClearElems(a,f,l,t) bzero(&(a)[f], ((l)-(f)+1) * sizeof(t))
#define _XkbFree(p) Xfree(p)
+/* Resizes array to hold new_num elements, zeroing newly added entries.
+ Destroys old array on failure. */
+#define _XkbResizeArray(array, old_num, new_num, type) \
+ do { \
+ if (array == NULL) { \
+ array = _XkbTypedCalloc(new_num, type); \
+ } else { \
+ type *prev_array = array; \
+ array = Xreallocarray(array, new_num, sizeof(type)); \
+ if (_X_UNLIKELY((array) == NULL)) { \
+ _XkbFree(prev_array); \
+ } else if ((new_num) > (old_num)) { \
+ bzero(&array[old_num], \
+ ((new_num) - (old_num)) * sizeof(type)); \
+ } \
+ } \
+ } while(0)
+
_XFUNCPROTOBEGIN
extern void _XkbReloadDpy(
diff --git a/nx-X11/lib/src/xlibi18n/ICWrap.c b/nx-X11/lib/src/xlibi18n/ICWrap.c
index 69f080d87..f5caafb97 100644
--- a/nx-X11/lib/src/xlibi18n/ICWrap.c
+++ b/nx-X11/lib/src/xlibi18n/ICWrap.c
@@ -66,6 +66,7 @@ from The Open Group.
#endif
#include "Xlibint.h"
#include "Xlcint.h"
+#include "reallocarray.h"
static int
_XIMNestedListToNestedList(
@@ -84,7 +85,7 @@ _XIMNestedListToNestedList(
nlist++;
}
}
- return ptr - list;
+ return (int) (ptr - list);
}
static void
@@ -128,7 +129,7 @@ _XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
return;
}
- args = Xmalloc(((unsigned)max_count + 1) * sizeof(XIMArg));
+ args = Xmallocarray((unsigned)max_count + 1, sizeof(XIMArg));
*args_return = args;
if (!args) return;
diff --git a/nx-X11/lib/src/xlibi18n/XimProto.h b/nx-X11/lib/src/xlibi18n/XimProto.h
index 6b0096dd6..cc7eda311 100644
--- a/nx-X11/lib/src/xlibi18n/XimProto.h
+++ b/nx-X11/lib/src/xlibi18n/XimProto.h
@@ -188,9 +188,9 @@ PERFORMANCE OF THIS SOFTWARE.
* request packet header size
*/
#define XIM_HEADER_SIZE \
- sizeof(CARD8) /* sizeof mejor-opcode */ \
+ ( sizeof(CARD8) /* sizeof major-opcode */ \
+ sizeof(CARD8) /* sizeof minor-opcode */ \
- + sizeof(INT16) /* sizeof length */
+ + sizeof(INT16) ) /* sizeof length */
/*
* Client Message data size
diff --git a/nx-X11/lib/src/xlibi18n/XlcPublic.h b/nx-X11/lib/src/xlibi18n/XlcPublic.h
index 3d94ef37d..bab7d6905 100644
--- a/nx-X11/lib/src/xlibi18n/XlcPublic.h
+++ b/nx-X11/lib/src/xlibi18n/XlcPublic.h
@@ -136,7 +136,7 @@ extern Bool _XlcAddCharSet(
/* Retrieves a number of attributes of an XlcCharSet.
Return NULL if successful, otherwise the name of the first argument
- specifiying a nonexistent attribute. */
+ specifying a nonexistent attribute. */
extern char *_XlcGetCSValues(
XlcCharSet charset,
...
diff --git a/nx-X11/lib/src/xlibi18n/Xlcint.h b/nx-X11/lib/src/xlibi18n/Xlcint.h
index 5a6205a1f..196d313f5 100644
--- a/nx-X11/lib/src/xlibi18n/Xlcint.h
+++ b/nx-X11/lib/src/xlibi18n/Xlcint.h
@@ -655,7 +655,7 @@ typedef struct {
/*
* An X Input Manager (IM). Implementations may need to extend this data
- * structure to accomodate additional data, state information etc.
+ * structure to accommodate additional data, state information etc.
*/
typedef struct _XIM {
XIMMethods methods; /* method list of this IM */
@@ -739,7 +739,7 @@ typedef struct {
/*
* an Input Context. Implementations may need to extend this data
- * structure to accomodate additional data, state information etc.
+ * structure to accommodate additional data, state information etc.
*/
typedef struct _XIC {
XICMethods methods; /* method list of this IC */
diff --git a/nx-X11/lib/src/xlibi18n/imKStoUCS.c b/nx-X11/lib/src/xlibi18n/imKStoUCS.c
index 640b3516a..a1c591211 100644
--- a/nx-X11/lib/src/xlibi18n/imKStoUCS.c
+++ b/nx-X11/lib/src/xlibi18n/imKStoUCS.c
@@ -131,8 +131,8 @@ static unsigned short const keysym_to_unicode_8a4_8fe[] = {
static unsigned short const keysym_to_unicode_9df_9f8[] = {
0x2422, /* 0x09d8-0x09df */
0x2666, 0x25a6, 0x2409, 0x240c, 0x240d, 0x240a, 0x0000, 0x0000, /* 0x09e0-0x09e7 */
- 0x240a, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x2500, /* 0x09e8-0x09ef */
- 0x0000, 0x0000, 0x0000, 0x0000, 0x251c, 0x2524, 0x2534, 0x252c, /* 0x09f0-0x09f7 */
+ 0x240a, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, /* 0x09e8-0x09ef */
+ 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, /* 0x09f0-0x09f7 */
0x2502 /* 0x09f8-0x09ff */
};
@@ -285,7 +285,7 @@ KeySymToUcs4(KeySym keysym)
return keysym_to_unicode_3a2_3fe[keysym - 0x3a2];
else if (keysym > 0x4a0 && keysym < 0x4e0)
return keysym_to_unicode_4a1_4df[keysym - 0x4a1];
- else if (keysym > 0x589 && keysym < 0x5ff)
+ else if (keysym > 0x58f && keysym < 0x5ff)
return keysym_to_unicode_590_5fe[keysym - 0x590];
else if (keysym > 0x67f && keysym < 0x700)
return keysym_to_unicode_680_6ff[keysym - 0x680];
diff --git a/nx-X11/lib/src/xlibi18n/lcCT.c b/nx-X11/lib/src/xlibi18n/lcCT.c
index a2ff93c8a..15e4ef233 100644
--- a/nx-X11/lib/src/xlibi18n/lcCT.c
+++ b/nx-X11/lib/src/xlibi18n/lcCT.c
@@ -323,7 +323,7 @@ _XlcParseCharSet(
if (*ptr == '\0')
return False;
- length = strlen(ptr);
+ length = (int) strlen(ptr);
type = _XlcParseCT(&ptr, &length, &final_byte);
@@ -428,7 +428,7 @@ _XlcGetCTInfo(
&& (type != XctExtSeg
|| (text_len >= ct_info->ext_segment_len
&& memcmp(text, ct_info->ext_segment,
- ct_info->ext_segment_len) == 0)))
+ (size_t) ct_info->ext_segment_len) == 0)))
return ct_info;
return (CTInfo) NULL;
@@ -477,7 +477,7 @@ _XlcAddCT(
}
/* Allocate a CTinfo record. */
- length = strlen(ct_sequence);
+ length = (int) strlen(ct_sequence);
ct_info = Xmalloc(sizeof(CTInfoRec) + length+1);
if (ct_info == NULL)
return charset;
@@ -506,7 +506,7 @@ _XlcAddCT(
/* By convention, the extended segment name is the encoding_name
in lowercase. */
const char *q = charset->encoding_name;
- int n = strlen(q);
+ int n = (int) strlen(q);
char *p;
/* Ensure ct_info->ext_segment_len <= 0x3fff - 6. */
@@ -802,7 +802,7 @@ cttocs(
int n = (state->ext_seg_left <= buf_len
? state->ext_seg_left
: (buf_len / char_size) * char_size);
- memcpy(bufptr, ctptr, n);
+ memcpy(bufptr, ctptr, (size_t) n);
ctptr += n; ctext_len -= n;
bufptr += n; buf_len -= n;
state->ext_seg_left -= n;
@@ -834,7 +834,7 @@ cttocs(
We may be splitting a character into multiple pieces.
Oh well. */
int n = buf_len;
- memcpy(bufptr, ctptr, n);
+ memcpy(bufptr, ctptr, (size_t) n);
ctptr += n; ctext_len -= n;
bufptr += n; buf_len -= n;
state->ext_seg_left -= n;
@@ -899,7 +899,7 @@ cstoct(
return -1;
side = charset->side;
- length = strlen(ct_info->ct_sequence);
+ length = (int) strlen(ct_info->ct_sequence);
ext_segment_start = NULL;
@@ -909,7 +909,7 @@ cstoct(
if (ct_len < length + 3)
return -1;
- memcpy(ctptr, ct_info->ct_sequence, length);
+ memcpy(ctptr, ct_info->ct_sequence, (size_t) length);
ctptr += length;
ct_len -= length + 3;
} else
@@ -924,7 +924,7 @@ cstoct(
if (ct_len < length + 2 + ct_info->ext_segment_len)
return -1;
- memcpy(ctptr, ct_info->ct_sequence, length);
+ memcpy(ctptr, ct_info->ct_sequence, (size_t) length);
ctptr += length;
ct_len -= length;
@@ -936,14 +936,14 @@ cstoct(
if (ct_len > 0x3fff)
ct_len = 0x3fff;
- memcpy(ctptr, ct_info->ext_segment, ct_info->ext_segment_len);
+ memcpy(ctptr, ct_info->ext_segment, (size_t) ct_info->ext_segment_len);
ctptr += ct_info->ext_segment_len;
ct_len -= ct_info->ext_segment_len;
} else {
if (ct_len < length)
return -1;
- memcpy(ctptr, ct_info->ct_sequence, length);
+ memcpy(ctptr, ct_info->ct_sequence, (size_t) length);
ctptr += length;
ct_len -= length;
}
diff --git a/nx-X11/lib/src/xlibi18n/lcCharSet.c b/nx-X11/lib/src/xlibi18n/lcCharSet.c
index 0adf0adfc..7f1452603 100644
--- a/nx-X11/lib/src/xlibi18n/lcCharSet.c
+++ b/nx-X11/lib/src/xlibi18n/lcCharSet.c
@@ -121,7 +121,7 @@ static XlcResource resources[] = {
/* Retrieves a number of attributes of an XlcCharSet.
Return NULL if successful, otherwise the name of the first argument
- specifiying a nonexistent attribute. */
+ specifying a nonexistent attribute. */
static char *
get_values(
XlcCharSet charset,
@@ -137,7 +137,7 @@ get_values(
/* Retrieves a number of attributes of an XlcCharSet.
Return NULL if successful, otherwise the name of the first argument
- specifiying a nonexistent attribute. */
+ specifying a nonexistent attribute. */
char *
_XlcGetCSValues(XlcCharSet charset, ...)
{
@@ -172,7 +172,7 @@ _XlcCreateDefaultCharSet(
const char *ct_sequence)
{
XlcCharSet charset;
- int name_len, ct_sequence_len;
+ size_t name_len, ct_sequence_len;
const char *colon;
char *tmp;
@@ -195,7 +195,7 @@ _XlcCreateDefaultCharSet(
/* Fill in encoding_name and xrm_encoding_name. */
if ((colon = strchr(charset->name, ':')) != NULL) {
- unsigned int length = colon - charset->name;
+ size_t length = (size_t)(colon - charset->name);
char *encoding_tmp = Xmalloc(length + 1);
if (encoding_tmp == NULL) {
Xfree((char *) charset->name);
diff --git a/nx-X11/lib/src/xlibi18n/lcConv.c b/nx-X11/lib/src/xlibi18n/lcConv.c
index 7d9a4738c..32699746d 100644
--- a/nx-X11/lib/src/xlibi18n/lcConv.c
+++ b/nx-X11/lib/src/xlibi18n/lcConv.c
@@ -29,6 +29,11 @@
#include "Xlibint.h"
#include "XlcPubI.h"
#include <stdio.h>
+#include "locking.h"
+
+#ifdef XTHREADS
+LockInfoPtr _conv_lock;
+#endif
typedef struct _XlcConverterListRec {
XLCd from_lcd;
@@ -58,6 +63,9 @@ get_converter(
XrmQuark to_type)
{
XlcConverterList list, prev = NULL;
+ XlcConv conv = NULL;
+
+ _XLockMutex(_conv_lock);
for (list = conv_list; list; list = list->next) {
if (list->from_lcd == from_lcd && list->to_lcd == to_lcd
@@ -69,13 +77,16 @@ get_converter(
conv_list = list;
}
- return (*list->converter)(from_lcd, list->from, to_lcd, list->to);
+ conv = (*list->converter)(from_lcd, list->from, to_lcd, list->to);
+ break;
}
prev = list;
}
- return (XlcConv) NULL;
+ _XUnlockMutex(_conv_lock);
+
+ return conv;
}
Bool
@@ -92,18 +103,20 @@ _XlcSetConverter(
from_type = XrmStringToQuark(from);
to_type = XrmStringToQuark(to);
+ _XLockMutex(_conv_lock);
+
for (list = conv_list; list; list = list->next) {
if (list->from_lcd == from_lcd && list->to_lcd == to_lcd
&& list->from_type == from_type && list->to_type == to_type) {
list->converter = converter;
- return True;
+ goto ret;
}
}
list = Xmalloc(sizeof(XlcConverterListRec));
if (list == NULL)
- return False;
+ goto ret;
list->from_lcd = from_lcd;
list->from = from;
@@ -115,7 +128,9 @@ _XlcSetConverter(
list->next = conv_list;
conv_list = list;
- return True;
+ret:
+ _XUnlockMutex(_conv_lock);
+ return list != NULL;
}
typedef struct _ConvRec {
diff --git a/nx-X11/lib/src/xlibi18n/lcDB.c b/nx-X11/lib/src/xlibi18n/lcDB.c
index eb46f8fbd..f25b98c29 100644
--- a/nx-X11/lib/src/xlibi18n/lcDB.c
+++ b/nx-X11/lib/src/xlibi18n/lcDB.c
@@ -39,6 +39,7 @@
#include <nx-X11/Xresource.h>
#include "Xlibint.h"
#include "XlcPubI.h"
+#include "reallocarray.h"
#else /* NOT_X_ENV */
@@ -294,7 +295,7 @@ zap_comment(
int pos = p - str;
if (pos == 0 ||
(iswhite(p[-1]) && (pos == 1 || p[-2] != SYM_BACKSLASH))) {
- int len = strlen(p);
+ int len = (int) strlen(p);
if (len > 0 && (p[len - 1] == SYM_NEWLINE || p[len-1] == SYM_CR)) {
/* newline is the identifier for finding end of value.
therefore, it should not be removed. */
@@ -326,7 +327,7 @@ read_line(
while ((p = fgets(buf, BUFSIZE, fd)) != NULL) {
++line->seq;
zap_comment(p, &quoted); /* remove comment line */
- len = strlen(p);
+ len = (int) strlen(p);
if (len == 0) {
if (cur > 0) {
break;
@@ -340,7 +341,7 @@ read_line(
}
str = line->str;
}
- strncpy(str + cur, p, len);
+ memcpy(str + cur, p, (size_t) len);
cur += len;
str[cur] = '\0';
@@ -413,7 +414,7 @@ get_word(
} else if (token != T_COMMENT && token != T_DEFAULT) {
break;
}
- strncpy(w, p, token_len);
+ strncpy(w, p, (size_t) token_len);
p += token_len; w += token_len;
}
*w = '\0';
@@ -448,7 +449,7 @@ get_quoted_word(
token = get_token(p);
token_len = token_tbl[token].len;
}
- strncpy(w, p, token_len);
+ strncpy(w, p, (size_t) token_len);
p += token_len; w += token_len;
}
/* error. cannot detect next double quote */
@@ -483,7 +484,7 @@ append_value_list (void)
char **prev_list = value_list;
value_list = (char **)
- Xrealloc(value_list, sizeof(char *) * (value_num + 2));
+ Xreallocarray(value_list, value_num + 2, sizeof(char *));
if (value_list == NULL) {
Xfree(prev_list);
}
@@ -507,17 +508,19 @@ append_value_list (void)
}
if (value != *value_list) {
int i;
- ssize_t delta;
- delta = value - *value_list;
+ char *old_list;
+ old_list = *value_list;
*value_list = value;
+ /* Re-derive pointers from the new realloc() result to avoid undefined
+ behaviour (and crashes on architectures with pointer bounds). */
for (i = 1; i < value_num; ++i) {
- value_list[i] += delta;
+ value_list[i] = value + (value_list[i] - old_list);
}
}
value_list[value_num] = p = &value[value_len];
value_list[value_num + 1] = NULL;
- strncpy(p, str, len);
+ strncpy(p, str, (size_t) len);
p[len] = 0;
parse_info.value = value_list;
@@ -551,7 +554,7 @@ construct_name(
char *p = name;
for (i = 0; i <= parse_info.nest_depth; ++i) {
- len += strlen(parse_info.name[i]) + 1;
+ len = (int) ((size_t) len + (strlen(parse_info.name[i]) + 1));
}
if (len >= size)
return 0;
@@ -655,8 +658,8 @@ check_category_end(
while (iswhite(*p)) {
++p;
}
- len = strlen(parse_info.category);
- if (strncmp(p, parse_info.category, len)) {
+ len = (int) strlen(parse_info.category);
+ if (strncmp(p, parse_info.category, (size_t) len)) {
return 0;
}
p += len;
@@ -806,7 +809,7 @@ f_double_quote(
char* wordp;
int len;
- if ((len = strlen (str)) < sizeof word)
+ if ((len = (int) strlen (str)) < sizeof word)
wordp = word;
else
wordp = Xmalloc (len + 1);
@@ -825,12 +828,12 @@ f_double_quote(
goto err;
if ((parse_info.bufsize + (int)strlen(wordp) + 1)
>= parse_info.bufMaxSize) {
- if (realloc_parse_info(strlen(wordp)+1) == False) {
+ if (realloc_parse_info((int) strlen(wordp)+1) == False) {
goto err;
}
}
strcpy(&parse_info.buf[parse_info.bufsize], wordp);
- parse_info.bufsize += strlen(wordp);
+ parse_info.bufsize = (int) ((size_t) parse_info.bufsize + strlen(wordp));
parse_info.pre_state = S_VALUE;
break;
default:
@@ -867,7 +870,7 @@ f_numeric(
int len;
int token_len;
- if ((len = strlen (str)) < sizeof word)
+ if ((len = (int) strlen (str)) < sizeof word)
wordp = word;
else
wordp = Xmalloc (len + 1);
@@ -887,12 +890,12 @@ f_numeric(
goto err;
if ((parse_info.bufsize + token_len + (int)strlen(wordp) + 1)
>= parse_info.bufMaxSize) {
- if (realloc_parse_info(token_len + strlen(wordp) + 1) == False)
+ if (realloc_parse_info((int)((size_t) token_len + strlen(wordp) + 1)) == False)
goto err;
}
- strncpy(&parse_info.buf[parse_info.bufsize], str, token_len);
+ strncpy(&parse_info.buf[parse_info.bufsize], str, (size_t) token_len);
strcpy(&parse_info.buf[parse_info.bufsize + token_len], wordp);
- parse_info.bufsize += token_len + strlen(wordp);
+ parse_info.bufsize = (int) ((size_t) parse_info.bufsize + ((size_t) token_len + strlen(wordp)));
parse_info.pre_state = S_VALUE;
break;
default:
@@ -918,7 +921,7 @@ f_default(
char* wordp;
int len;
- if ((len = strlen (str)) < sizeof word)
+ if ((len = (int) strlen (str)) < sizeof word)
wordp = word;
else
wordp = Xmalloc (len + 1);
@@ -945,7 +948,7 @@ f_default(
/* end of category is detected.
clear context and zap to end of this line */
clear_parse_info();
- len = strlen(str);
+ len = (int) strlen(str);
break;
}
}
@@ -962,11 +965,11 @@ f_default(
case S_VALUE:
if ((parse_info.bufsize + (int)strlen(wordp) + 1)
>= parse_info.bufMaxSize) {
- if (realloc_parse_info(strlen(wordp) + 1) == False)
+ if (realloc_parse_info((int) strlen(wordp) + 1) == False)
goto err;
}
strcpy(&parse_info.buf[parse_info.bufsize], wordp);
- parse_info.bufsize += strlen(wordp);
+ parse_info.bufsize = (int) ((size_t) parse_info.bufsize + strlen(wordp));
parse_info.pre_state = S_VALUE;
break;
default:
@@ -1223,7 +1226,7 @@ _XlcGetLocaleDataBase(
/* _XlcDestroyLocaleDataBase(lcd) */
/*----------------------------------------------------------------------*/
/* This function destroy the XLocale Database that bound to the */
-/* specified lcd. If the XLocale Database is refered from some */
+/* specified lcd. If the XLocale Database is referred from some */
/* other lcd, this function just decreases reference count of */
/* the database. If no locale refers the database, this function */
/* remove it from the cache list and free work area. */
diff --git a/nx-X11/lib/src/xlibi18n/lcFile.c b/nx-X11/lib/src/xlibi18n/lcFile.c
index cf03a90a7..e4fc8a00b 100644
--- a/nx-X11/lib/src/xlibi18n/lcFile.c
+++ b/nx-X11/lib/src/xlibi18n/lcFile.c
@@ -36,6 +36,9 @@
/************************************************************************/
+#ifndef HAVE_SETEUID
+# define seteuid setuid
+#endif
#define iscomment(ch) ((ch) == '#' || (ch) == '\0')
#if defined(WIN32)
#define isreadable(f) (_XAccessFile(f))
@@ -142,7 +145,7 @@ _XlcParsePath(
for (i = 0; i < n; ++i) {
int len;
p = argv[i];
- len = strlen(p);
+ len = (int) strlen(p);
if (len > 0 && p[len - 1] == '/') {
/* eliminate trailing slash */
p[len - 1] = '\0';
@@ -172,7 +175,7 @@ xlocaledir(
if (dir) {
#ifndef WIN32
/*
- * Only use the user-supplied path if the process isn't priviledged.
+ * Only use the user-supplied path if the process isn't privileged.
*/
if (getuid() == geteuid() && getgid() == getegid()) {
#if defined(HASSETUGID)
@@ -187,7 +190,7 @@ xlocaledir(
}
#else
/*
- * If there are saved ID's the process might still be priviledged
+ * If there are saved ID's the process might still be privileged
* even though the above test succeeded. If issetugid() and
* getresgid() aren't available, test this by trying to set
* euid to 0.
@@ -202,7 +205,7 @@ xlocaledir(
priv = 0;
} else {
if (seteuid(oldeuid) == -1) {
- /* XXX ouch, coudn't get back to original uid
+ /* XXX ouch, couldn't get back to original uid
what can we do ??? */
_exit(127);
}
@@ -214,8 +217,8 @@ xlocaledir(
priv = 0;
#endif
if (!priv) {
- len = strlen(dir);
- strncpy(p, dir, buf_len);
+ len = (int) strlen(dir);
+ strncpy(p, dir, (size_t) buf_len);
if (len < buf_len) {
p[len++] = LC_PATHDELIM;
p += len;
@@ -225,7 +228,7 @@ xlocaledir(
#endif /* NO_XLOCALEDIR */
if (len < buf_len)
- strncpy(p, XLOCALEDIR, buf_len - len);
+ strncpy(p, XLOCALEDIR, (size_t) (buf_len - len));
buf[buf_len-1] = '\0';
}
@@ -246,7 +249,7 @@ xlocalelibdir(
if (dir) {
#ifndef WIN32
/*
- * Only use the user-supplied path if the process isn't priviledged.
+ * Only use the user-supplied path if the process isn't privileged.
*/
if (getuid() == geteuid() && getgid() == getegid()) {
#if defined(HASSETUGID)
@@ -261,7 +264,7 @@ xlocalelibdir(
}
#else
/*
- * If there are saved ID's the process might still be priviledged
+ * If there are saved ID's the process might still be privileged
* even though the above test succeeded. If issetugid() and
* getresgid() aren't available, test this by trying to set
* euid to 0.
@@ -276,7 +279,7 @@ xlocalelibdir(
priv = 0;
} else {
if (seteuid(oldeuid) == -1) {
- /* XXX ouch, coudn't get back to original uid
+ /* XXX ouch, couldn't get back to original uid
what can we do ??? */
_exit(127);
}
@@ -288,8 +291,8 @@ xlocalelibdir(
priv = 0;
#endif
if (!priv) {
- len = strlen(dir);
- strncpy(p, dir, buf_len);
+ len = (int) strlen(dir);
+ strncpy(p, dir, (size_t) buf_len);
if (len < buf_len) {
p[len++] = LC_PATHDELIM;
p += len;
@@ -299,7 +302,7 @@ xlocalelibdir(
#endif /* NO_XLOCALEDIR */
if (len < buf_len)
- strncpy(p, XLOCALELIBDIR, buf_len - len);
+ strncpy(p, XLOCALELIBDIR, (size_t) (buf_len - len));
buf[buf_len-1] = '\0';
}
@@ -361,7 +364,7 @@ lowercase(
char *t;
for (s = src, t = dst; *s; ++s, ++t)
- *t = c_tolower(*s);
+ *t = (char) c_tolower(*s);
*t = '\0';
return dst;
}
@@ -387,7 +390,7 @@ normalize_lcname (const char *name)
*p++ = *tmp++;
while (*tmp) {
if (*tmp != '-')
- *p++ = c_tolower(*tmp);
+ *p++ = (char) c_tolower(*tmp);
tmp++;
}
}
@@ -504,7 +507,7 @@ _XlcResolveLocaleName(
pub->siname = name;
}
- sinamelen = strlen (pub->siname);
+ sinamelen = (int) strlen (pub->siname);
if (sinamelen == 1 && pub->siname[0] == 'C') {
pub->language = pub->siname;
pub->territory = pub->codeset = NULL;
diff --git a/nx-X11/lib/src/xlibi18n/lcGeneric.c b/nx-X11/lib/src/xlibi18n/lcGeneric.c
index f816fee77..1f3f60bb0 100644
--- a/nx-X11/lib/src/xlibi18n/lcGeneric.c
+++ b/nx-X11/lib/src/xlibi18n/lcGeneric.c
@@ -34,6 +34,7 @@
#include <stdio.h>
#include "Xlibint.h"
#include "XlcGeneric.h"
+#include "reallocarray.h"
static XLCd create (const char *name, XLCdMethods methods);
static Bool initialize (XLCd lcd);
@@ -157,8 +158,8 @@ add_charset(
int num;
if ((num = codeset->num_charsets))
- new_list = Xrealloc(codeset->charset_list,
- (num + 1) * sizeof(XlcCharSet));
+ new_list = Xreallocarray(codeset->charset_list,
+ num + 1, sizeof(XlcCharSet));
else
new_list = Xmalloc(sizeof(XlcCharSet));
@@ -184,8 +185,8 @@ add_codeset(
return NULL;
if ((num = gen->codeset_num))
- new_list = Xrealloc(gen->codeset_list,
- (num + 1) * sizeof(CodeSet));
+ new_list = Xreallocarray(gen->codeset_list,
+ num + 1, sizeof(CodeSet));
else
new_list = Xmalloc(sizeof(CodeSet));
@@ -231,8 +232,8 @@ add_parse_list(
}
if ((num = gen->mb_parse_list_num))
- new_list = Xrealloc(gen->mb_parse_list,
- (num + 2) * sizeof(ParseInfo));
+ new_list = Xreallocarray(gen->mb_parse_list,
+ num + 2, sizeof(ParseInfo));
else {
new_list = Xmalloc(2 * sizeof(ParseInfo));
}
@@ -275,16 +276,22 @@ free_charset(
int num;
Xfree(gen->mb_parse_table);
+ gen->mb_parse_table = NULL;
if ((num = gen->mb_parse_list_num) > 0) {
for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) {
Xfree((*parse_info)->encoding);
Xfree(*parse_info);
}
Xfree(gen->mb_parse_list);
+ gen->mb_parse_list = NULL;
+ gen->mb_parse_list_num = 0;
}
- if ((num = gen->codeset_num) > 0)
+ if ((num = gen->codeset_num) > 0) {
Xfree(gen->codeset_list);
+ gen->codeset_list = NULL;
+ gen->codeset_num = 0;
+ }
}
/* For VW/UDC */
@@ -350,7 +357,7 @@ _XlcParse_scopemaps(
const char *str_sc;
num = count_scopemap(str);
- scope = Xmalloc(num * sizeof(FontScopeRec));
+ scope = Xmallocarray(num, sizeof(FontScopeRec));
if (scope == NULL)
return NULL;
@@ -535,8 +542,8 @@ add_conversion(
int num;
if ((num = gen->segment_conv_num) > 0) {
- new_list = Xrealloc(gen->segment_conv,
- (num + 1) * sizeof(SegConvRec));
+ new_list = Xreallocarray(gen->segment_conv,
+ num + 1, sizeof(SegConvRec));
} else {
new_list = Xmalloc(sizeof(SegConvRec));
}
@@ -667,7 +674,7 @@ create_ctextseg(
ret->side = XlcGLGR;
strcpy(cset_name,ret->name);
}
- ret->area = Xmalloc((num - 1)*sizeof(FontScopeRec));
+ ret->area = Xmallocarray(num - 1, sizeof(FontScopeRec));
if (ret->area == NULL) {
Xfree (cset_name);
Xfree (ret->name);
@@ -795,7 +802,7 @@ load_generic(
EncodingType type = E_SS; /* for BC */
for (j = 0; shifts[j].str; j++) {
if (!_XlcNCompareISOLatin1(tmp, shifts[j].str,
- strlen(shifts[j].str))) {
+ (int) strlen(shifts[j].str))) {
type = shifts[j].type;
tmp += strlen(shifts[j].str);
break;
@@ -870,8 +877,8 @@ load_generic(
codeset->byteM = NULL;
break ;
}
- codeset->byteM = Xmalloc(
- (codeset->length)*sizeof(ByteInfoListRec));
+ codeset->byteM = Xmallocarray(codeset->length,
+ sizeof(ByteInfoListRec));
if (codeset->byteM == NULL) {
goto err;
}
@@ -882,7 +889,7 @@ load_generic(
(codeset->byteM)[M-1].M = M;
(codeset->byteM)[M-1].byteinfo_num = num;
(codeset->byteM)[M-1].byteinfo =
- Xmalloc(num * sizeof(ByteInfoRec));
+ Xmallocarray(num, sizeof(ByteInfoRec));
for (ii = 0 ; ii < num ; ii++) {
tmpb = (codeset->byteM)[M-1].byteinfo ;
/* default 0x00 - 0xff */
diff --git a/nx-X11/lib/src/xlibi18n/lcPrTxt.c b/nx-X11/lib/src/xlibi18n/lcPrTxt.c
index e62e94e80..047eb7f7a 100644
--- a/nx-X11/lib/src/xlibi18n/lcPrTxt.c
+++ b/nx-X11/lib/src/xlibi18n/lcPrTxt.c
@@ -30,6 +30,7 @@
#include "XlcPubI.h"
#include <nx-X11/Xutil.h>
#include <nx-X11/Xatom.h>
+#include "reallocarray.h"
static XPointer *
alloc_list(
@@ -40,11 +41,11 @@ alloc_list(
if (is_wide_char) {
wchar_t **wstr_list;
- wstr_list = Xmalloc(count * sizeof(wchar_t *));
+ wstr_list = Xmallocarray(count, sizeof(wchar_t *));
if (wstr_list == NULL)
return (XPointer *) NULL;
- *wstr_list = Xmalloc(nitems * sizeof(wchar_t));
+ *wstr_list = Xmallocarray(nitems, sizeof(wchar_t));
if (*wstr_list == NULL) {
Xfree(wstr_list);
return (XPointer *) NULL;
@@ -54,7 +55,7 @@ alloc_list(
} else {
char **str_list;
- str_list = Xmalloc(count * sizeof(char *));
+ str_list = Xmallocarray(count, sizeof(char *));
if (str_list == NULL)
return (XPointer *) NULL;
@@ -99,7 +100,7 @@ copy_list(
for (str = *str_list; count > 0; count--, str_list++) {
strcpy(str, mb_text);
*str_list = str;
- length = strlen(str) + 1;
+ length = (int) strlen(str) + 1;
str += length;
mb_text += length;
}
@@ -185,7 +186,7 @@ _XTextPropertyToTextList(
if (do_strcpy) {
len = min(from_left, to_left);
- strncpy(to, from, len);
+ strncpy(to, from, (size_t) len);
from += len;
to += len;
from_left -= len;
diff --git a/nx-X11/lib/src/xlibi18n/lcPublic.c b/nx-X11/lib/src/xlibi18n/lcPublic.c
index f35f17a63..1cbc212dc 100644
--- a/nx-X11/lib/src/xlibi18n/lcPublic.c
+++ b/nx-X11/lib/src/xlibi18n/lcPublic.c
@@ -219,7 +219,7 @@ initialize(
* _XlMapOSLocaleName will return the same string or a substring
* of name, so strlen(name) is okay
*/
- if ((len = strlen(name)) < sizeof sinamebuf)
+ if ((len = (int) strlen(name)) < sizeof sinamebuf)
siname = sinamebuf;
else
siname = Xmalloc (len + 1);
@@ -258,6 +258,7 @@ destroy_core(
if (lcd) {
if (lcd->core) {
Xfree(lcd->core->name);
+ Xfree(lcd->core->modifiers);
Xfree(lcd->core);
}
Xfree(lcd->methods);
diff --git a/nx-X11/lib/src/xlibi18n/lcStd.c b/nx-X11/lib/src/xlibi18n/lcStd.c
index 9d452bcae..a8518b056 100644
--- a/nx-X11/lib/src/xlibi18n/lcStd.c
+++ b/nx-X11/lib/src/xlibi18n/lcStd.c
@@ -36,11 +36,11 @@ _Xlcmbtowc(
char *str,
int len)
{
- static XLCd last_lcd = NULL;
- static XlcConv conv = NULL;
+ XlcConv conv;
XPointer from, to;
int from_left, to_left;
wchar_t tmp_wc;
+ int ret;
if (lcd == NULL) {
lcd = _XlcCurrentLC();
@@ -50,18 +50,9 @@ _Xlcmbtowc(
if (str == NULL)
return XLC_PUBLIC(lcd, is_state_depend);
- if (conv && lcd != last_lcd) {
- _XlcCloseConverter(conv);
- conv = NULL;
- }
-
- last_lcd = lcd;
-
- if (conv == NULL) {
- conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar);
- if (conv == NULL)
+ conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar);
+ if (conv == NULL)
return -1;
- }
from = (XPointer) str;
from_left = len;
@@ -69,9 +60,12 @@ _Xlcmbtowc(
to_left = 1;
if (_XlcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0)
- return -1;
+ ret = -1;
+ else
+ ret = len - from_left;
- return (len - from_left);
+ _XlcCloseConverter(conv);
+ return ret;
}
int
@@ -80,10 +74,10 @@ _Xlcwctomb(
char *str,
wchar_t wc)
{
- static XLCd last_lcd = NULL;
- static XlcConv conv = NULL;
+ XlcConv conv;
XPointer from, to;
int from_left, to_left, length;
+ int ret;
if (lcd == NULL) {
lcd = _XlcCurrentLC();
@@ -93,18 +87,9 @@ _Xlcwctomb(
if (str == NULL)
return XLC_PUBLIC(lcd, is_state_depend);
- if (conv && lcd != last_lcd) {
- _XlcCloseConverter(conv);
- conv = NULL;
- }
-
- last_lcd = lcd;
-
- if (conv == NULL) {
- conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte);
- if (conv == NULL)
- return -1;
- }
+ conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte);
+ if (conv == NULL)
+ return -1;
from = (XPointer) &wc;
from_left = 1;
@@ -112,9 +97,12 @@ _Xlcwctomb(
length = to_left = XLC_PUBLIC(lcd, mb_cur_max);
if (_XlcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0)
- return -1;
+ ret = -1;
+ else
+ ret = length - to_left;
- return (length - to_left);
+ _XlcCloseConverter(conv);
+ return ret;
}
int
@@ -139,7 +127,7 @@ _Xlcmbstowcs(
return -1;
from = (XPointer) str;
- from_left = strlen(str);
+ from_left = (int) strlen(str);
to = (XPointer) wstr;
to_left = len;
@@ -279,7 +267,7 @@ _Xwcslen(
while (*wstr_ptr)
wstr_ptr++;
- return wstr_ptr - wstr;
+ return (int) (wstr_ptr - wstr);
}
int
@@ -331,7 +319,7 @@ _Xlcmbstoutf8(
return -1;
from = (XPointer) str;
- from_left = strlen(str);
+ from_left = (int) strlen(str);
to = (XPointer) ustr;
to_left = len;
diff --git a/nx-X11/lib/src/xlibi18n/lcTxtPr.c b/nx-X11/lib/src/xlibi18n/lcTxtPr.c
index cf25e3d0e..102d2917b 100644
--- a/nx-X11/lib/src/xlibi18n/lcTxtPr.c
+++ b/nx-X11/lib/src/xlibi18n/lcTxtPr.c
@@ -56,7 +56,7 @@ get_buf_size(
mb_list = (char **) list;
for ( ; count-- > 0; mb_list++) {
if (*mb_list)
- length += strlen(*mb_list) + 1;
+ length = (int) ((size_t) length + (strlen(*mb_list) + 1));
}
length *= 3; /* XXX */
}
@@ -118,7 +118,7 @@ _XTextListToTextProperty(
strcpy(to, *mb_list);
else
*to = '\0';
- from_left = (*mb_list ? strlen(*mb_list) : 0) + 1;
+ from_left = (int) (*mb_list ? strlen(*mb_list) : 0) + 1;
nitems += from_left;
to += from_left;
mb_list++;
@@ -161,7 +161,7 @@ retry:
wc_list++;
} else {
from = (XPointer) *mb_list;
- from_left = (*mb_list ? strlen(*mb_list) : 0);
+ from_left = (int) (*mb_list ? strlen(*mb_list) : 0);
mb_list++;
}
@@ -190,7 +190,7 @@ retry:
_XlcCloseConverter(conv);
- nitems = to - buf;
+ nitems = (int) (to - buf);
done:
if (nitems <= 0)
nitems = 1;
@@ -202,14 +202,14 @@ done:
if (nitems == 1)
*value = 0;
else
- memcpy(value, buf, nitems);
+ memcpy(value, buf, (size_t) nitems);
nitems--;
Xfree(buf);
text_prop->value = (unsigned char *) value;
text_prop->encoding = encoding;
text_prop->format = 8;
- text_prop->nitems = nitems;
+ text_prop->nitems = (unsigned long) nitems;
return unconv_num;
}
diff --git a/nx-X11/lib/src/xlibi18n/lcUTF8.c b/nx-X11/lib/src/xlibi18n/lcUTF8.c
index 5899338f1..8169608ad 100644
--- a/nx-X11/lib/src/xlibi18n/lcUTF8.c
+++ b/nx-X11/lib/src/xlibi18n/lcUTF8.c
@@ -163,6 +163,9 @@ typedef struct _Utf8ConvRec {
#include "lcUniConv/utf8.h"
#include "lcUniConv/ucs2be.h"
+#ifdef notused
+#include "lcUniConv/ascii.h"
+#endif
#include "lcUniConv/iso8859_1.h"
#include "lcUniConv/iso8859_2.h"
#include "lcUniConv/iso8859_3.h"
@@ -739,20 +742,14 @@ utf8tocs1(
continue;
}
+ last_charset = _XlcGetCharSetWithSide(chosen_charset->name, chosen_side);
+
if (last_charset == NULL) {
- last_charset =
- _XlcGetCharSetWithSide(chosen_charset->name, chosen_side);
- if (last_charset == NULL) {
- src += consumed;
- unconv_num++;
- continue;
- }
- } else {
- if (!(last_charset->xrm_encoding_name == chosen_charset->xrm_name
- && (last_charset->side == XlcGLGR
- || last_charset->side == chosen_side)))
- break;
+ src += consumed;
+ unconv_num++;
+ continue;
}
+
src += consumed;
dst += count;
break;
@@ -1612,20 +1609,14 @@ wcstocs1(
continue;
}
+ last_charset = _XlcGetCharSetWithSide(chosen_charset->name, chosen_side);
+
if (last_charset == NULL) {
- last_charset =
- _XlcGetCharSetWithSide(chosen_charset->name, chosen_side);
- if (last_charset == NULL) {
- src++;
- unconv_num++;
- continue;
- }
- } else {
- if (!(last_charset->xrm_encoding_name == chosen_charset->xrm_name
- && (last_charset->side == XlcGLGR
- || last_charset->side == chosen_side)))
- break;
+ src++;
+ unconv_num++;
+ continue;
}
+
src++;
dst += count;
break;
@@ -1724,7 +1715,7 @@ create_tofontcs_conv(
{
XlcConv conv;
int i, num, k, count;
- char **value, buf[20];
+ char **value, buf[32];
Utf8Conv *preferred;
lazy_init_all_charsets();
@@ -1931,7 +1922,7 @@ iconv_mbstocs(XlcConv conv, XPointer *from, int *from_left,
/* Uses stdc iconv to convert multibyte -> widechar */
- consumed = mbtowc(&wc, (const char *)src, srcend-src);
+ consumed = mbtowc(&wc, (const char *)src, (size_t) (srcend - src));
if (consumed == 0)
break;
if (consumed == -1) {
@@ -2027,7 +2018,7 @@ iconv_mbtocs(XlcConv conv, XPointer *from, int *from_left,
/* Uses stdc iconv to convert multibyte -> widechar */
- consumed = mbtowc(&wc, (const char *)src, srcend-src);
+ consumed = mbtowc(&wc, (const char *)src, (size_t) (srcend - src));
if (consumed == 0)
break;
if (consumed == -1) {
@@ -2117,7 +2108,7 @@ iconv_mbstostr(XlcConv conv, XPointer *from, int *from_left,
/* Uses stdc iconv to convert multibyte -> widechar */
- consumed = mbtowc(&wc, (const char *)src, srcend-src);
+ consumed = mbtowc(&wc, (const char *)src, (size_t) (srcend - src));
if (consumed == 0)
break;
if (dst == dstend)
@@ -2221,7 +2212,7 @@ iconv_mbstowcs(XlcConv conv, XPointer *from, int *from_left,
int length, unconv_num = 0;
while (src_left > 0 && dst_left > 0) {
- length = mbtowc(dst, src, src_left);
+ length = mbtowc(dst, src, (size_t) src_left);
if (length > 0) {
src += length;
@@ -2355,6 +2346,7 @@ _XlcAddUtf8LocaleConverters(
/* Register converters for XlcNFontCharSet */
_XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNFontCharSet, open_utf8tofcs);
_XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNFontCharSet, open_wcstofcs);
+ _XlcSetConverter(lcd, XlcNUtf8String, lcd, XlcNFontCharSet, open_utf8tofcs);
}
void
diff --git a/nx-X11/lib/src/xlibi18n/lcUtil.c b/nx-X11/lib/src/xlibi18n/lcUtil.c
index 52a16daea..30e9c85d9 100644
--- a/nx-X11/lib/src/xlibi18n/lcUtil.c
+++ b/nx-X11/lib/src/xlibi18n/lcUtil.c
@@ -34,7 +34,7 @@
#define set_toupper(ch) \
if (ch >= 'a' && ch <= 'z') \
- ch = ch - 'a' + 'A';
+ ch = (unsigned char) (ch - 'a' + 'A');
/* Compares two ISO 8859-1 strings, ignoring case of ASCII letters.
Like strcasecmp in an ASCII locale. */
@@ -46,8 +46,8 @@ _XlcCompareISOLatin1(
unsigned char ch1, ch2;
for ( ; ; str1++, str2++) {
- ch1 = *str1;
- ch2 = *str2;
+ ch1 = (unsigned char) *str1;
+ ch2 = (unsigned char) *str2;
if (ch1 == '\0' || ch2 == '\0')
break;
set_toupper(ch1);
@@ -72,8 +72,8 @@ _XlcNCompareISOLatin1(
for ( ; ; str1++, str2++, len--) {
if (len == 0)
return 0;
- ch1 = *str1;
- ch2 = *str2;
+ ch1 = (unsigned char) *str1;
+ ch2 = (unsigned char) *str2;
if (ch1 == '\0' || ch2 == '\0')
break;
set_toupper(ch1);
diff --git a/nx-X11/lib/src/xlibi18n/lcWrap.c b/nx-X11/lib/src/xlibi18n/lcWrap.c
index 067c501ba..bc7db1837 100644
--- a/nx-X11/lib/src/xlibi18n/lcWrap.c
+++ b/nx-X11/lib/src/xlibi18n/lcWrap.c
@@ -66,6 +66,7 @@ from The Open Group.
#endif
#include <nx-X11/Xutil.h>
#include "XlcPubI.h"
+#include "reallocarray.h"
#ifdef XTHREADS
LockInfoPtr _Xi18n_lock;
@@ -110,8 +111,8 @@ Bool _XlcValidModSyntax(
if (*mods == '@')
break;
for (ptr = valid_mods; *ptr; ptr++) {
- i = strlen(*ptr);
- if (strncmp(mods, *ptr, i) || ((mods[i] != '=')
+ i = (int) strlen(*ptr);
+ if (strncmp(mods, *ptr, (size_t) i) || ((mods[i] != '=')
#ifdef WIN32
&& (mods[i] != '#')
#endif
@@ -140,9 +141,9 @@ _XlcDefaultMapModifiers(
return (char *)NULL;
if (!_XlcValidModSyntax(user_mods, im_valid))
return (char *)NULL;
- i = strlen(prog_mods) + 1;
+ i = (int) strlen(prog_mods) + 1;
if (user_mods)
- i += strlen(user_mods);
+ i = (int) ((size_t) i + strlen(user_mods));
mods = Xmalloc(i);
if (mods) {
strcpy(mods, prog_mods);
@@ -168,7 +169,6 @@ _XlcDefaultMapModifiers(
typedef struct _XLCdListRec {
struct _XLCdListRec *next;
XLCd lcd;
- int ref_count;
} XLCdListRec, *XLCdList;
static XLCdList lcd_list = NULL;
@@ -261,7 +261,7 @@ _XOpenLC(
* _XlMapOSLocaleName will return the same string or a substring
* of name, so strlen(name) is okay
*/
- if ((len = strlen(name)) >= sizeof sinamebuf) {
+ if ((len = (int) strlen(name)) >= sizeof sinamebuf) {
siname = Xmalloc (len + 1);
if (siname == NULL)
return NULL;
@@ -278,7 +278,6 @@ _XOpenLC(
for (cur = lcd_list; cur; cur = cur->next) {
if (!strcmp (cur->lcd->core->name, name)) {
lcd = cur->lcd;
- cur->ref_count++;
goto found;
}
}
@@ -295,7 +294,6 @@ _XOpenLC(
cur = Xmalloc (sizeof(XLCdListRec));
if (cur) {
cur->lcd = lcd;
- cur->ref_count = 1;
cur->next = lcd_list;
lcd_list = cur;
} else {
@@ -322,23 +320,7 @@ void
_XCloseLC(
XLCd lcd)
{
- XLCdList cur, *prev;
-
- for (prev = &lcd_list; (cur = *prev); prev = &cur->next) {
- if (cur->lcd == lcd) {
- if (--cur->ref_count < 1) {
- (*lcd->methods->close)(lcd);
- *prev = cur->next;
- Xfree(cur);
- }
- break;
- }
- }
-
- if(loader_list) {
- _XlcDeInitLoader();
- loader_list = NULL;
- }
+ (void) lcd;
}
/*
@@ -348,17 +330,7 @@ _XCloseLC(
XLCd
_XlcCurrentLC(void)
{
- XLCd lcd;
- static XLCd last_lcd = NULL;
-
- lcd = _XOpenLC((char *) NULL);
-
- if (last_lcd)
- _XCloseLC(last_lcd);
-
- last_lcd = lcd;
-
- return lcd;
+ return _XOpenLC(NULL);
}
XrmMethods
@@ -514,9 +486,9 @@ _XlcCopyFromArg(
else if (size == sizeof(XPointer))
*((XPointer *) dst) = (XPointer) src;
else if (size > sizeof(XPointer))
- memcpy(dst, (char *) src, size);
+ memcpy(dst, (char *) src, (size_t) size);
else
- memcpy(dst, (char *) &src, size);
+ memcpy(dst, (char *) &src, (size_t) size);
}
void
@@ -540,7 +512,7 @@ _XlcCopyToArg(
else if (size == sizeof(XPointer))
*((XPointer *) *dst) = *((XPointer *) src);
else
- memcpy(*dst, src, size);
+ memcpy(*dst, src, (size_t) size);
}
void
@@ -564,7 +536,7 @@ _XlcVaToArgList(
{
XlcArgList args;
- *args_ret = args = Xmalloc(sizeof(XlcArg) * count);
+ *args_ret = args = Xmallocarray(count, sizeof(XlcArg));
if (args == (XlcArgList) NULL)
return;