[前][次][番号順一覧][スレッド一覧]

ruby-changes:30155

From: nobu <ko1@a...>
Date: Sun, 28 Jul 2013 10:54:43 +0900 (JST)
Subject: [ruby-changes:30155] nobu:r42207 (trunk): win32.c: fix pipe name formatting

nobu	2013-07-28 10:54:30 +0900 (Sun, 28 Jul 2013)

  New Revision: 42207

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42207

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42206)
+++ ChangeLog	(revision 42207)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jul 28 10:54:26 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@f...>
 
 	* bignum.c (rb_big_size): Return the bignum "bytewise" size.
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 42206)
+++ win32/win32.c	(revision 42207)
@@ -5654,8 +5654,12 @@ int https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5654
 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]) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5669
     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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]