Use strlcpy when no formatting is required

This commit is contained in:
libretroadmin 2024-06-13 07:02:38 +02:00
parent 3e2e53ba7f
commit af11f8f54c
2 changed files with 60 additions and 49 deletions

View File

@ -79,7 +79,7 @@ static void gl3_framebuffer_copy(
glUseProgram(quad_program);
if (flat_ubo_vertex >= 0)
{
static float mvp[16] = {
static float mvp[16] = {
2.0f, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f, 0.0f, 0.0f,
0.0f, 0.0f, 2.0f, 0.0f,
@ -111,7 +111,7 @@ static void gl3_framebuffer_copy(
static void gl3_framebuffer_copy_partial(
GLuint fb_id,
GLuint quad_program,
GLuint quad_program,
GLint flat_ubo_vertex,
struct Size2D size,
GLuint image,
@ -138,7 +138,7 @@ static void gl3_framebuffer_copy_partial(
glUseProgram(quad_program);
if (flat_ubo_vertex >= 0)
{
static float mvp[16] = {
static float mvp[16] = {
2.0f, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f, 0.0f, 0.0f,
0.0f, 0.0f, 2.0f, 0.0f,
@ -213,7 +213,7 @@ static uint32_t gl3_get_cross_compiler_target_version(void)
#ifdef HAVE_OPENGLES3
if (!version || sscanf(version, "OpenGL ES %u.%u", &major, &minor) != 2)
return 300;
if (major == 2 && minor == 0)
return 100;
#else
@ -935,12 +935,12 @@ public:
current_subframe = cur_subframe;
}
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
void set_simulate_scanline(bool simulate)
{
simulate_scanline = simulate;
}
#endif // GL3_ROLLING_SCANLINE_SIMULATION
#endif /* GL3_ROLLING_SCANLINE_SIMULATION */
void set_name(const char *name)
{
@ -1043,9 +1043,9 @@ private:
unsigned pass_number = 0;
uint32_t total_subframes = 1;
uint32_t current_subframe = 1;
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
bool simulate_scanline = false;
#endif // GL3_ROLLING_SCANLINE_SIMULATION
#endif /* GL3_ROLLING_SCANLINE_SIMULATION */
size_t ubo_offset = 0;
std::string pass_name;
@ -1170,7 +1170,8 @@ void Pass::reflect_parameter_array(const char *name, std::vector<slang_texture_s
for (i = 0; i < meta.size(); i++)
{
char n[128];
snprintf(n, sizeof(n), "%s%u", name, (unsigned)i);
size_t _len = strlcpy(n, name, sizeof(n));
snprintf(n + _len, sizeof(n) - _len, "%u", (unsigned)i);
slang_texture_semantic_meta *m = (slang_texture_semantic_meta*)&meta[i];
if (m->uniform)
@ -1178,13 +1179,15 @@ void Pass::reflect_parameter_array(const char *name, std::vector<slang_texture_s
int vert, frag;
char vert_n[256];
char frag_n[256];
snprintf(vert_n, sizeof(vert_n), "RARCH_UBO_VERTEX_INSTANCE.%s", n);
snprintf(frag_n, sizeof(frag_n), "RARCH_UBO_FRAGMENT_INSTANCE.%s", n);
size_t _len = strlcpy(vert_n, "RARCH_UBO_VERTEX_INSTANCE.", sizeof(vert_n));
size_t _len2 = strlcpy(frag_n, "RARCH_UBO_FRAGMENT_INSTANCE.", sizeof(frag_n));
strlcpy(vert_n + _len, n, sizeof(vert_n) - _len);
strlcpy(frag_n + _len2, n, sizeof(frag_n) - _len2);
vert = glGetUniformLocation(pipeline, vert_n);
frag = glGetUniformLocation(pipeline, frag_n);
if (vert >= 0)
m->location.ubo_vertex = vert;
m->location.ubo_vertex = vert;
if (frag >= 0)
m->location.ubo_fragment = frag;
}
@ -1194,8 +1197,10 @@ void Pass::reflect_parameter_array(const char *name, std::vector<slang_texture_s
int vert, frag;
char vert_n[256];
char frag_n[256];
snprintf(vert_n, sizeof(vert_n), "RARCH_PUSH_VERTEX_INSTANCE.%s", n);
snprintf(frag_n, sizeof(frag_n), "RARCH_PUSH_FRAGMENT_INSTANCE.%s", n);
size_t _len = strlcpy(vert_n, "RARCH_PUSH_VERTEX_INSTANCE.", sizeof(vert_n));
size_t _len2 = strlcpy(frag_n, "RARCH_PUSH_FRAGMENT_INSTANCE.", sizeof(frag_n));
strlcpy(vert_n + _len, n, sizeof(vert_n) - _len);
strlcpy(frag_n + _len2, n, sizeof(frag_n) - _len2);
vert = glGetUniformLocation(pipeline, vert_n);
frag = glGetUniformLocation(pipeline, frag_n);
@ -1360,7 +1365,7 @@ void Pass::build_semantic_vec4(uint8_t *data, slang_semantic semantic,
if (refl->push_constant)
{
if ( refl->location.push_vertex >= 0 ||
if ( refl->location.push_vertex >= 0 ||
refl->location.push_fragment >= 0)
{
float v4[4];
@ -1668,8 +1673,8 @@ void Pass::build_semantics(uint8_t *buffer,
unsigned(current_viewport.height));
build_semantic_uint(buffer, SLANG_SEMANTIC_FRAME_COUNT,
frame_count_period
? uint32_t(frame_count % frame_count_period)
frame_count_period
? uint32_t(frame_count % frame_count_period)
: uint32_t(frame_count));
build_semantic_int(buffer, SLANG_SEMANTIC_FRAME_DIRECTION,
@ -1765,7 +1770,7 @@ void Pass::build_commands(
GLsizei((reflection.push_constant_size + 15) / 16),
reinterpret_cast<const float *>(push_constant_buffer.data()));
if (!( locations.buffer_index_ubo_vertex == GL_INVALID_INDEX
if (!( locations.buffer_index_ubo_vertex == GL_INVALID_INDEX
&& locations.buffer_index_ubo_fragment == GL_INVALID_INDEX))
{
/* UBO Ring - update and bind */
@ -1800,22 +1805,22 @@ void Pass::build_commands(
glClear(GL_COLOR_BUFFER_BIT);
}
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
if (simulate_scanline)
{
glEnable(GL_SCISSOR_TEST);
}
#endif // GL3_ROLLING_SCANLINE_SIMULATION
#endif /* GL3_ROLLING_SCANLINE_SIMULATION */
if (final_pass)
{
glViewport(current_viewport.x, current_viewport.y,
current_viewport.width, current_viewport.height);
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
if (simulate_scanline)
{
glScissor( current_viewport.x,
int32_t((float(current_viewport.height) / float(total_subframes))
int32_t((float(current_viewport.height) / float(total_subframes))
* float(current_subframe - 1)),
current_viewport.width,
uint32_t(float(current_viewport.height) / float(total_subframes))
@ -1823,20 +1828,20 @@ void Pass::build_commands(
}
else
{
glScissor( current_viewport.x, current_viewport.y,
glScissor( current_viewport.x, current_viewport.y,
current_viewport.width, current_viewport.height);
}
#endif // GL3_ROLLING_SCANLINE_SIMULATION
}
#endif /* GL3_ROLLING_SCANLINE_SIMULATION */
}
else
{
glViewport(0, 0, size.width, size.height);
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
if (simulate_scanline)
{
glScissor( 0,
int32_t((float(size.height) / float(total_subframes))
int32_t((float(size.height) / float(total_subframes))
* float(current_subframe - 1)),
size.width,
uint32_t(float(size.height) / float(total_subframes))
@ -1845,8 +1850,8 @@ void Pass::build_commands(
else
{
glScissor(0, 0, size.width, size.height);
}
#endif // GL3_ROLLING_SCANLINE_SIMULATION
}
#endif /* GL3_ROLLING_SCANLINE_SIMULATION */
}
#if !defined(HAVE_OPENGLES)
@ -1871,12 +1876,12 @@ void Pass::build_commands(
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
if (simulate_scanline)
{
glDisable(GL_SCISSOR_TEST);
}
#endif // GL3_ROLLING_SCANLINE_SIMULATION
#endif /* GL3_ROLLING_SCANLINE_SIMULATION */
#if !defined(HAVE_OPENGLES)
glDisable(GL_FRAMEBUFFER_SRGB);
@ -1929,9 +1934,9 @@ public:
void set_rotation(uint32_t rot);
void set_shader_subframes(uint32_t tot_subframes);
void set_current_shader_subframe(uint32_t cur_subframe);
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
void set_simulate_scanline(bool simulate);
#endif // GL3_ROLLING_SCANLINE_SIMULATION
#endif /* GL3_ROLLING_SCANLINE_SIMULATION */
void set_pass_name(unsigned pass, const char *name);
void add_static_texture(std::unique_ptr<gl3_shader::StaticTexture> texture);
@ -2008,7 +2013,7 @@ void gl3_filter_chain::build_offscreen_passes(const gl3_viewport &vp)
{
unsigned i;
/* First frame, make sure our history and feedback textures
/* First frame, make sure our history and feedback textures
* are in a clean state. */
if (require_clear)
{
@ -2060,7 +2065,7 @@ void gl3_filter_chain::end_frame()
if (input_texture.width != tmp->get_size().width ||
input_texture.height != tmp->get_size().height ||
(input_texture.format != 0
(input_texture.format != 0
&& input_texture.format != tmp->get_format()))
tmp->set_size({ input_texture.width, input_texture.height }, input_texture.format);
@ -2083,7 +2088,7 @@ void gl3_filter_chain::build_viewport_pass(
const gl3_viewport &vp, const float *mvp)
{
unsigned i;
/* First frame, make sure our history and
/* First frame, make sure our history and
* feedback textures are in a clean state. */
if (require_clear)
{
@ -2215,7 +2220,7 @@ bool gl3_filter_chain::init_feedback()
bool gl3_filter_chain::init_alias()
{
int i;
common.texture_semantic_map.clear();
common.texture_semantic_uniform_map.clear();
@ -2382,9 +2387,9 @@ void gl3_filter_chain::set_input_texture(
common.quad_loc.flat_ubo_vertex,
copy_framebuffer->get_size(),
input_texture.image,
float(input_texture.width)
float(input_texture.width)
/ input_texture.padded_width,
float(input_texture.height)
float(input_texture.height)
/ input_texture.padded_height);
input_texture.image = copy_framebuffer->get_image();
}
@ -2435,14 +2440,14 @@ void gl3_filter_chain::set_current_shader_subframe(uint32_t cur_subframe)
passes[i]->set_current_shader_subframe(cur_subframe);
}
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
void gl3_filter_chain::set_simulate_scanline(bool simulate_scanline)
{
unsigned i;
for (i = 0; i < passes.size(); i++)
passes[i]->set_simulate_scanline(simulate_scanline);
}
#endif // GL3_ROLLING_SCANLINE_SIMULATION
#endif /* GL3_ROLLING_SCANLINE_SIMULATION */
void gl3_filter_chain::set_pass_name(unsigned pass, const char *name)
{
@ -2564,7 +2569,7 @@ gl3_filter_chain_t *gl3_filter_chain_create_from_preset(
if (!chain)
return nullptr;
if ( shader->luts
if ( shader->luts
&& !gl3_filter_chain_load_luts(chain.get(), shader.get()))
return nullptr;
@ -2663,8 +2668,8 @@ gl3_filter_chain_t *gl3_filter_chain_create_from_preset(
else
{
pass_info.source_filter =
pass->filter == RARCH_FILTER_LINEAR
? GLSLANG_FILTER_CHAIN_LINEAR
pass->filter == RARCH_FILTER_LINEAR
? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST;
}
pass_info.address = rarch_wrap_to_address(pass->wrap);
@ -2678,7 +2683,7 @@ gl3_filter_chain_t *gl3_filter_chain_create_from_preset(
pass_info.max_levels = ~0u;
pass_info.mip_filter = pass->filter != RARCH_FILTER_NEAREST && pass_info.max_levels > 1
? GLSLANG_FILTER_CHAIN_LINEAR
? GLSLANG_FILTER_CHAIN_LINEAR
: GLSLANG_FILTER_CHAIN_NEAREST;
bool explicit_format = output.meta.rt_format != SLANG_FORMAT_UNKNOWN;
@ -2878,14 +2883,14 @@ void gl3_filter_chain_set_current_shader_subframe(
chain->set_current_shader_subframe(cur_subframe);
}
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
void gl3_filter_chain_set_simulate_scanline(
gl3_filter_chain_t *chain,
bool simulate_scanline)
{
chain->set_simulate_scanline(simulate_scanline);
}
#endif // GL3_ROLLING_SCANLINE_SIMULATION
#endif /* GL3_ROLLING_SCANLINE_SIMULATION */
void gl3_filter_chain_set_frame_count_period(
gl3_filter_chain_t *chain,

View File

@ -232,7 +232,10 @@ static bool slang_process_reflection(
{
size = sizeof(names) / sizeof(*names);
if (semantic < size)
snprintf(texture.id, sizeof(texture.id), "%s%d", names[_semantic], index);
{
size_t _len = strlcpy(texture.id, names[_semantic], sizeof(texture.id));
snprintf(texture.id + _len, sizeof(texture.id) - _len, "%d", index);
}
else
strlcpy(texture.id, get_semantic_name(sl_reflection.texture_semantic_map, _semantic, index), sizeof(texture.id));
}
@ -279,7 +282,10 @@ static bool slang_process_reflection(
{
int size = sizeof(names) / sizeof(*names);
if (semantic < size)
snprintf(uniform.id, sizeof(uniform.id), "%s%d", names[_semantic], index);
{
size_t _len = strlcpy(uniform.id, names[_semantic], sizeof(uniform.id));
snprintf(uniform.id + _len, sizeof(uniform.id) - _len, "%d", index);
}
else
strlcpy(uniform.id, get_semantic_name(sl_reflection.texture_semantic_uniform_map, _semantic, index), sizeof(uniform.id));
}