Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU: try to retrive 0 element from vector #38

Closed
KennyProgrammer opened this issue May 8, 2023 · 2 comments
Closed

GPU: try to retrive 0 element from vector #38

KennyProgrammer opened this issue May 8, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@KennyProgrammer
Copy link

KennyProgrammer commented May 8, 2023

In GPU class in one of Win32 getVendor, getName, getDriverVersion, you try retrive 0 element from vector, and then you check if ret is string is empty, but if vector is empty and you try to retrive 0 element is crashed.

How it was:

std::string GPU::getVendor() {
  std::vector<const wchar_t*> vendor{};
  wmi::queryWMI("WIN32_VideoController", "AdapterCompatibility", vendor);
  auto ret = vendor[0];
  if (!ret) {
    return "<unknown>";
  }
  std::wstring tmp(ret);
  return {tmp.begin(), tmp.end()};
}

How it should be :

std::string GPU::getVendor() {
  std::vector<const wchar_t*> vendor{};
  wmi::queryWMI("WIN32_VideoController", "AdapterCompatibility", vendor);
  if(vendor.empty())
    return "<unknown>";

  auto ret = vendor[0];
  std::wstring tmp(ret);
  return {tmp.begin(), tmp.end()};
}

Please fix this with all this functions, even if library cannot retrive some hardware properties it at least should return unknown but not a crash.

@lfreist
Copy link
Owner

lfreist commented May 8, 2023

Hi, thanks for pointing this out. I'll fix it

@lfreist lfreist added the bug Something isn't working label May 8, 2023
@lfreist lfreist self-assigned this May 8, 2023
@KennyProgrammer
Copy link
Author

Thanks) Also you have the same issue in Win32 Motherboard class.

And another bug I've found that when on Windows multiple times use CoInitialize and CoUninitialize, it crashes or not retriving the next info at all (first info fine), so l've try to initialize it once and when all information I need I get then uninitialize it. Maybe it problem with my project because somewhere I already call this.

For test I create init.h and init.cpp files with init(), close() functions, then move initialization/uninitialization code there, and between them retrieve relevant information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants