[v0.20] Properly check GPU index range

This commit is contained in:
Dr-Noob
2021-12-21 17:09:32 +01:00
parent a20e93f4db
commit 4921660c24
2 changed files with 9 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
#include <cstdlib>
#include <cstdio>
#include "global.hpp"
#include "colors.hpp"
#include "master.hpp"
#include "../cuda/cuda.hpp"
@@ -78,6 +79,10 @@ int get_num_gpus_available(struct gpu_list* list) {
}
struct gpu_info* get_gpu_info(struct gpu_list* list, int idx) {
if(idx >= list->num_gpus || idx < 0) {
printErr("Specified GPU index is out of range: %d", idx);
return NULL;
}
return list->gpus[idx];
}