From f84c6ec8cd16d9ccb65778649b0365e83271d8d5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 2 Oct 2020 20:57:29 +0200 Subject: [PATCH] Use STRLEN_CONST where possible; and don't needlessly do strlen twice --- gfx/drivers_context/x_ctx.c | 8 +++++--- libretro-common/net/net_socket_ssl_bear.c | 16 ++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/gfx/drivers_context/x_ctx.c b/gfx/drivers_context/x_ctx.c index 155956994d..365a0d9743 100644 --- a/gfx/drivers_context/x_ctx.c +++ b/gfx/drivers_context/x_ctx.c @@ -124,19 +124,21 @@ static int GLXExtensionSupported(Display *dpy, const char *extension) const char *extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy)); const char *client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS); const char *pos = strstr(extensionsString, extension); + size_t pos_ext_len = strlen(extension); if ( pos && (pos == extensionsString || pos[-1] == ' ') && - (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0') + (pos[pos_ext_len] == ' ' || pos[pos_ext_len] == '\0') ) return 1; - pos = strstr(client_extensions, extension); + pos = strstr(client_extensions, extension); + pos_ext_len = strlen(extension); if ( pos && (pos == extensionsString || pos[-1] == ' ') && - (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0') + (pos[pos_ext_len] == ' ' || pos[pos_ext_len] == '\0') ) return 1; diff --git a/libretro-common/net/net_socket_ssl_bear.c b/libretro-common/net/net_socket_ssl_bear.c index 87d40d60f1..c14cd32581 100644 --- a/libretro-common/net/net_socket_ssl_bear.c +++ b/libretro-common/net/net_socket_ssl_bear.c @@ -24,8 +24,11 @@ #include #include #include +#include + #include "../../deps/bearssl-0.6/inc/bearssl.h" +/* TODO/FIXME - static global variables */ static br_x509_trust_anchor TAs[500] = {}; static size_t TAs_NUM = 0; @@ -113,16 +116,17 @@ static void append_certs_pem_x509(char * certs_pem) void * cert_bin; int cert_bin_len; - while (true) + for (;;) { cert = strstr(cert_end, "-----BEGIN CERTIFICATE-----"); - if (!cert) break; - cert += strlen("-----BEGIN CERTIFICATE-----"); - cert_end = strstr(cert, "-----END CERTIFICATE-----"); - + if (!cert) + break; + cert += STRLEN_CONST("-----BEGIN CERTIFICATE-----"); + cert_end = strstr(cert, "-----END CERTIFICATE-----"); + *cert_end = '\0'; cert = delete_linebreaks(cert); - + cert_bin = unbase64(cert, cert_end-cert, &cert_bin_len); append_cert_x509(cert_bin, cert_bin_len); free(cert_bin);