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

Fix strlen usage #10

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/backends/sdl2_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SOFTWARE.

#include <cassert>
#include <iostream>
#include <string_view>

namespace tinyui {
namespace {
Expand Down Expand Up @@ -62,8 +63,8 @@ void showDriverInUse(const Context &ctx) {
printDriverInfo(info);
}

int queryDriver(const Context &ctx, const char *driverType, size_t maxLen) {
if (driverType == nullptr) {
int queryDriver(const Context &ctx, const std::string_view &driverType) {
if (driverType.empty()) {
ctx.mLogger(LogSeverity::Error, "Driver type is a nullptr.");
return -1;
}
Expand All @@ -73,11 +74,7 @@ int queryDriver(const Context &ctx, const char *driverType, size_t maxLen) {
for (int i = 0; i < numRenderDrivers; ++i) {
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(i, &info);
size_t len = strlen(driverType);
if (len > maxLen) {
len = maxLen;
}
if (strncmp(driverType, info.name, len) == 0) {
if (driverType == std::string(info.name)) {
found = i;
break;
}
Expand Down Expand Up @@ -267,7 +264,7 @@ ret_code Renderer::initScreen(Context &ctx, int32_t x, int32_t y, int32_t w, int
return ErrorCode;
}

const int driverIndex = queryDriver(ctx, "opengl", 256);
const int driverIndex = queryDriver(ctx, std::string("opengl"));
if (driverIndex == -1) {
ctx.mLogger(LogSeverity::Error, "Cannot open opengl driver");
return ErrorCode;
Expand Down
Loading