? win32-low.c.ok ? x Index: win32-low.c =================================================================== RCS file: /cvs/src/src/gdb/gdbserver/win32-low.c,v retrieving revision 1.38 diff -u -r1.38 win32-low.c --- win32-low.c 4 Jul 2009 18:13:28 -0000 1.38 +++ win32-low.c 8 Jul 2009 11:29:25 -0000 @@ -922,7 +922,6 @@ DWORD size = unicode ? sizeof (WCHAR) : sizeof (char); char *address_ptr; int len = 0; - char b[2]; DWORD done; /* Attempt to read the name of the dll that was detected. @@ -945,21 +944,23 @@ return NULL; #endif - /* Find the length of the string */ - while (ReadProcessMemory (h, address_ptr + len++ * size, &b, size, &done) - && (b[0] != 0 || b[size - 1] != 0) && done == size) - continue; + /* ReadProcessMemory sometimes fails when reading a (w)char at a time, but + * we can't just read MAX_PATH (w)chars either : msdn says not to cross the + * boundary into inaccessible areas. + * So we loop, reading more characters each time, until we find the NULL. + */ + WCHAR *wbuf = alloca ((MAX_PATH + 1) * size); + while (1) + { + ReadProcessMemory (h, address_ptr, wbuf, ++len * size, &done); + if (wbuf[len - 1] == 0) + break; + } if (!unicode) ReadProcessMemory (h, address_ptr, buf, len, &done); else - { - WCHAR *unicode_address = (WCHAR *) alloca (len * sizeof (WCHAR)); - ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof (WCHAR), - &done); - - WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, len, 0, 0); - } + WideCharToMultiByte (CP_ACP, 0, wbuf, len, buf, len, 0, 0); return buf; }