Skip to content

Commit

Permalink
Merge pull request #1043 from nullif/enum-processes-fix
Browse files Browse the repository at this point in the history
EnumProcesses returns the byte count not length
  • Loading branch information
anaisbetts authored Jun 8, 2017
2 parents f411ed2 + 9bd6976 commit 022a805
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Squirrel/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,18 +789,18 @@ static unsafe class UnsafeUtility
{
public static List<Tuple<string, int>> EnumerateProcesses()
{
int length = 0;
int bytesReturned = 0;
var pids = new int[2048];

fixed(int* p = pids) {
if (!NativeMethods.EnumProcesses((IntPtr)p, sizeof(int) * pids.Length, out length)) {
if (!NativeMethods.EnumProcesses((IntPtr)p, sizeof(int) * pids.Length, out bytesReturned)) {
throw new Win32Exception("Failed to enumerate processes");
}

if (length < 1) throw new Exception("Failed to enumerate processes");
if (bytesReturned < 1) throw new Exception("Failed to enumerate processes");
}

return Enumerable.Range(0, length)
return Enumerable.Range(0, bytesReturned / sizeof(int))
.Where(i => pids[i] > 0)
.Select(i => {
try {
Expand Down

0 comments on commit 022a805

Please sign in to comment.