Skip to content

Commit

Permalink
Merge pull request #10 from kimkulling/fix/remove_strlen
Browse files Browse the repository at this point in the history
Fix strlen usage
  • Loading branch information
kimkulling authored Jan 21, 2025
2 parents f40cf68 + bb26562 commit 9a44779
Showing 1 changed file with 5 additions and 8 deletions.
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

0 comments on commit 9a44779

Please sign in to comment.