about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/sched/affinity.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/sched/affinity.c b/src/sched/affinity.c
index 3b402111..737e41b5 100644
--- a/src/sched/affinity.c
+++ b/src/sched/affinity.c
@@ -1,5 +1,6 @@
 #define _GNU_SOURCE
 #include <sched.h>
+#include <string.h>
 #include "pthread_impl.h"
 #include "syscall.h"
 
@@ -16,7 +17,10 @@ int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set)
 int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
 {
 	long ret = __syscall(SYS_sched_getaffinity, tid, size, set);
-	if (ret > 0) ret = 0;
+	if (ret > 0) {
+		if (ret < size) memset((char *)set+ret, 0, size-ret);
+		ret = 0;
+	}
 	return __syscall_ret(ret);
 }