mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-11-12 14:57:20 +00:00
[common/client] windows: avoid deprecated CRT calls
This commit is contained in:
@@ -234,7 +234,11 @@ static bool savePreset(struct EGL_PostProcess * this, const char * name)
|
||||
FILE * file = lgOpenFile(path, "w");
|
||||
if (!file)
|
||||
{
|
||||
const char * strError = strerror(errno);
|
||||
const int errorCode = errno;
|
||||
char strError[256] = { 0 };
|
||||
if (!lgFileErrorString(errorCode, strError, sizeof(strError)))
|
||||
snprintf(strError, sizeof(strError), "Error %d", errorCode);
|
||||
|
||||
DEBUG_ERROR("Failed to open preset \"%s\" for writing: %s", name, strError);
|
||||
free(path);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "common/stringutils.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -384,12 +385,22 @@ bool egl_shaderCompile(EGL_Shader * this, const char * vertex_code,
|
||||
}
|
||||
}
|
||||
|
||||
int processedLen = fragment_size;
|
||||
int processedLen = fragment_size;
|
||||
const char * defineFormat = "#define %s %s\n";
|
||||
for(const EGL_ShaderDefine * define = defines; define->name; ++define)
|
||||
processedLen += snprintf(NULL, 0, defineFormat, define->name, define->value);
|
||||
{
|
||||
const int defineLength = snprintf(
|
||||
NULL, 0, defineFormat, define->name, define->value);
|
||||
if (defineLength < 0 || processedLen > INT_MAX - defineLength)
|
||||
{
|
||||
DEBUG_ERROR("Failed to format shader defines");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
processed = malloc(processedLen);
|
||||
processedLen += defineLength;
|
||||
}
|
||||
|
||||
processed = malloc((size_t)processedLen + 1);
|
||||
if (!processed)
|
||||
{
|
||||
DEBUG_ERROR("Out of memory");
|
||||
@@ -400,13 +411,24 @@ bool egl_shaderCompile(EGL_Shader * this, const char * vertex_code,
|
||||
|
||||
int offset = insertPos;
|
||||
for(const EGL_ShaderDefine * define = defines; define->name; ++define)
|
||||
offset += sprintf(processed + offset, defineFormat,
|
||||
define->name, define->value);
|
||||
{
|
||||
const size_t available = (size_t)(processedLen - offset) + 1;
|
||||
const int written = snprintf(processed + offset, available,
|
||||
defineFormat, define->name, define->value);
|
||||
if (written < 0 || (size_t)written >= available)
|
||||
{
|
||||
DEBUG_ERROR("Failed to format shader defines");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
offset += written;
|
||||
}
|
||||
|
||||
memcpy(
|
||||
processed + offset,
|
||||
fragment_code + insertPos,
|
||||
fragment_size - insertPos);
|
||||
processed[processedLen] = '\0';
|
||||
|
||||
fragment_code = processed;
|
||||
fragment_size = processedLen;
|
||||
|
||||
@@ -840,14 +840,12 @@ static char * optPosToString(struct Option * opt)
|
||||
if (g_params.center)
|
||||
return lg_strdup("center");
|
||||
|
||||
int len = snprintf(NULL, 0, "%dx%d", g_params.x, g_params.y);
|
||||
char * str = malloc(len + 1);
|
||||
if (!str)
|
||||
char * str;
|
||||
if (alloc_sprintf(&str, "%dx%d", g_params.x, g_params.y) < 0)
|
||||
{
|
||||
DEBUG_ERROR("out of memory");
|
||||
return NULL;
|
||||
}
|
||||
sprintf(str, "%dx%d", g_params.x, g_params.y);
|
||||
|
||||
return str;
|
||||
}
|
||||
@@ -877,14 +875,12 @@ static StringList optSizeValues(struct Option * opt)
|
||||
|
||||
static char * optSizeToString(struct Option * opt)
|
||||
{
|
||||
int len = snprintf(NULL, 0, "%ux%u", g_params.w, g_params.h);
|
||||
char * str = malloc(len + 1);
|
||||
if (!str)
|
||||
char * str;
|
||||
if (alloc_sprintf(&str, "%ux%u", g_params.w, g_params.h) < 0)
|
||||
{
|
||||
DEBUG_ERROR("out of memory");
|
||||
return NULL;
|
||||
}
|
||||
sprintf(str, "%ux%u", g_params.w, g_params.h);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user