diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-28 01:54:30 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-28 01:54:30 +0000 |
commit | 56150eba928407b5b1410219292caf095db5ee63 (patch) | |
tree | 98aa7e8b1863297293ea31e55e338ea1414c4a6e | |
parent | b592a740fcb178a4de545081a9faffbd8f137e4d (diff) |
win32.c: fix pipe name formatting
* win32/win32.c (rb_w32_pipe): fix pipe name formatting. as "%x" may
not contain '0' at all, fill at fixed position instead.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | win32/win32.c | 13 |
2 files changed, 14 insertions, 4 deletions
@@ -1,3 +1,8 @@ +Sun Jul 28 10:54:26 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * win32/win32.c (rb_w32_pipe): fix pipe name formatting. as "%x" may + not contain '0' at all, fill at fixed position instead. + Sun Jul 28 00:35:14 2013 Tanaka Akira <akr@fsij.org> * bignum.c (rb_big_size): Return the bignum "bytewise" size. diff --git a/win32/win32.c b/win32/win32.c index 291dc2aebe..55a73b4056 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -5654,8 +5654,12 @@ int rb_w32_pipe(int fds[2]) { static DWORD serial = 0; - char name[] = "\\\\.\\pipe\\ruby0000000000000000-0000000000000000"; - char *p; + static const char prefix[] = "\\\\.\\pipe\\ruby"; + const int width_of_prefix = (int)sizeof(prefix) - 1; + const int width_of_pid = (int)sizeof(rb_pid_t) * 2; + const int width_of_serial = (int)sizeof(serial) * 2; + const int width_of_ids = width_of_pid + 1 + width_of_serial + 1; + char name[sizeof(prefix) + width_of_ids]; SECURITY_ATTRIBUTES sec; HANDLE hRead, hWrite, h; int fdRead, fdWrite; @@ -5665,8 +5669,9 @@ rb_w32_pipe(int fds[2]) if (!cancel_io) return _pipe(fds, 65536L, _O_NOINHERIT); - p = strchr(name, '0'); - snprintf(p, strlen(p) + 1, "%"PRI_PIDT_PREFIX"x-%lx", rb_w32_getpid(), serial++); + memcpy(name, prefix, width_of_prefix); + snprintf(name + width_of_prefix, width_of_ids, "%.*"PRI_PIDT_PREFIX"x-%.*lx", + width_of_pid, rb_w32_getpid(), width_of_serial, serial++); sec.nLength = sizeof(sec); sec.lpSecurityDescriptor = NULL; |