aboutsummaryrefslogtreecommitdiff
path: root/libxcb/src/xcb_util.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-04-30 14:06:28 +0000
committermarha <marha@users.sourceforge.net>2010-04-30 14:06:28 +0000
commit567e9524c7a2fdabade9cdbb672a55f6a417ce15 (patch)
treeace2565a2ab2b560c932145bacaa0ed02fdd537c /libxcb/src/xcb_util.c
parent4901672daffde38bee1212b50ca11fbe05f70c24 (diff)
downloadvcxsrv-567e9524c7a2fdabade9cdbb672a55f6a417ce15.tar.gz
vcxsrv-567e9524c7a2fdabade9cdbb672a55f6a417ce15.tar.bz2
vcxsrv-567e9524c7a2fdabade9cdbb672a55f6a417ce15.zip
libxcb git update 30/4/2010
Diffstat (limited to 'libxcb/src/xcb_util.c')
-rw-r--r--libxcb/src/xcb_util.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index 287f12fd9..cc4e24af2 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -145,8 +145,9 @@ static int _xcb_open(char *host, char *protocol, const int display)
#endif
static const char unix_base[] = "/tmp/.X11-unix/X";
const char *base = unix_base;
- char file[PATH_MAX + 1];
- int filelen;
+ size_t filelen;
+ char *file = NULL;
+ int actual_filelen;
if(*host)
{
@@ -181,24 +182,38 @@ static int _xcb_open(char *host, char *protocol, const int display)
#endif
}
+ filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
+ file = malloc(filelen);
+ if(file == NULL)
+ return -1;
+
/* display specifies Unix socket */
#ifdef HAVE_LAUNCHD
if(base == host)
- filelen = snprintf(file, sizeof(file), "%s:%d", base, display);
+ actual_filelen = snprintf(file, filelen, "%s:%d", base, display);
else
#endif
- filelen = snprintf(file, sizeof(file), "%s%d", base, display);
- if(filelen < 0)
+ actual_filelen = snprintf(file, filelen, "%s%d", base, display);
+ if(actual_filelen < 0)
+ {
+ free(file);
return -1;
+ }
/* snprintf may truncate the file */
- filelen = MIN(filelen, sizeof(file) - 1);
+ filelen = MIN(actual_filelen, filelen - 1);
#ifdef HAVE_ABSTRACT_SOCKETS
fd = _xcb_open_abstract(protocol, file, filelen);
if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED))
+ {
+ free(file);
return fd;
+ }
#endif
- return _xcb_open_unix(protocol, file);
+ fd = _xcb_open_unix(protocol, file);
+ free(file);
+
+ return fd;
}
static int _xcb_socket(int family, int type, int proto)